Karthikeya Boyini has Published 2193 Articles

Compare Two Java int Arrays in Java

karthikeya Boyini

karthikeya Boyini

Updated on 26-Jun-2020 10:53:52

555 Views

To compare two Java short arrays, use the Arrays.equals() method.Let us first declare and initialize some int arrays.int[] arr1 = new int[] { 33, 66, 12, 56, 99 }; int[] arr2 = new int[] { 33, 66, 12, 56, 99 }; int[] arr3 = new int[] { 33, 66, 15, ... Read More

How to assign int value to char variable in Java

karthikeya Boyini

karthikeya Boyini

Updated on 26-Jun-2020 10:52:45

2K+ Views

To assign int value to a char variable in Java would consider the ASCII value and display the associated character/ digit.Here, we have a char.char val;Now assign int value to it.val = 77;Now, when you will print the value of “val”, it would display the character associate with the value ... Read More

Java Program to create a boolean variable from string

karthikeya Boyini

karthikeya Boyini

Updated on 26-Jun-2020 10:47:48

319 Views

Use the parseBoolean() method to create a boolean variable from a string. Here for boolean variable, firstly take a boolean and pass the string to it using Boolean.parseBoolean().boolean val1 = Boolean.parseBoolean("TRUE");The parseBoolean() parses the string argument as a boolean. The boolean returned represents the value true if the string argument ... Read More

Parse and format a number to octal in Java

karthikeya Boyini

karthikeya Boyini

Updated on 26-Jun-2020 10:46:33

739 Views

To parse and format a number to octal, try the following code −Example Live Demopublic class Demo {    public static void main( String args[] ) {       int val = Integer.parseInt("150", 8);       System.out.println(val);       String str = Integer.toString(val, 8);       System.out.println(str); ... Read More

Random number generator in Java

karthikeya Boyini

karthikeya Boyini

Updated on 26-Jun-2020 10:45:38

3K+ Views

To generate random numbers in Java, use.import java.util.Random;Now, take Random class and create an object.Random num = new Random();Now, in a loop, use the nextInt() method since it is used to get the next random integer value. You can also set a range, like for 0 to 20, write it ... Read More

Check two numbers for equality in Java

karthikeya Boyini

karthikeya Boyini

Updated on 26-Jun-2020 10:44:37

11K+ Views

To check two numbers for equality in Java, we can use the Equals() method as well as the == operator.Firstly, let us set Integers.Integer val1 = new Integer(5); Integer val2 = new Integer(5);Now, to check whether they are equal or not, let us use the == operator.(val1 == val2)Let us ... Read More

Java Program to convert hexadecimal number to decimal number

karthikeya Boyini

karthikeya Boyini

Updated on 26-Jun-2020 10:42:43

439 Views

Use the parseInt() method with the second parameter as 16 since it is the radix value. The parseInt() method has the following two forms.static int parseInt(String s) static int parseInt(String s, int radix)To convert hex string to decimal, use the 2nd syntax and add radix as 16, since hexadecimal radix ... Read More

Boolean Literals in Java

karthikeya Boyini

karthikeya Boyini

Updated on 26-Jun-2020 10:40:43

791 Views

The Boolean literals have two values i.e. True and False.The following is an example to display Boolean Literals.Example Live Demopublic class Demo {    public static void main(String[] args) {       System.out.println("Boolean Literals");       boolean one = true;       System.out.println(one);       one = ... Read More

Integer.signum() method in Java

karthikeya Boyini

karthikeya Boyini

Updated on 26-Jun-2020 10:39:47

146 Views

The method returns the signum function of the specified int value. Let us now see the syntax.int signum(int i)Here is the parameter.i − This is the int valueThe return value is -1 if the specified value is negative, 0 if the specified value is zero and 1 if the specified ... Read More

Convert Java Boolean Primitive to Boolean object

karthikeya Boyini

karthikeya Boyini

Updated on 26-Jun-2020 10:38:52

4K+ Views

To convert Boolean Primitive to Boolean object, use the valueOf() method in Java.Firstly, let us take a boolean primitive.boolean val = false;To convert it into an object, use the valueOf() method and set the argument as the boolean primitive.Boolean res = Boolean.valueOf(val);Let us see the complete example to learn how ... Read More

Advertisements