Java Articles

Page 442 of 450

Java Boolean operators

Fendadis John
Fendadis John
Updated on 30-Jul-2019 10K+ Views

There are following boolean operators supported by Java language.Assume variable A holds 10 and variable B holds 20, then −OperatorDescriptionExample== (equal to)Checks if the values of two operands are equal or not, if yes then condition becomes true.(A == B) is not true.!= (not equal to)Checks if the values of two operands are equal or not, if values are not equal then condition becomes true.(A != B) is true.> (greater than)Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true.(A > B) is not true.< (less than)Checks if the ...

Read More

Java Boolean operators

Fendadis John
Fendadis John
Updated on 30-Jul-2019 10K+ Views

There are following boolean operators supported by Java language.Assume variable A holds 10 and variable B holds 20, then −OperatorDescriptionExample== (equal to)Checks if the values of two operands are equal or not, if yes then condition becomes true.(A == B) is not true.!= (not equal to)Checks if the values of two operands are equal or not, if values are not equal then condition becomes true.(A != B) is true.> (greater than)Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true.(A > B) is not true.< (less than)Checks if the ...

Read More

Differences between & and && operators in Java.

Kumar Varma
Kumar Varma
Updated on 30-Jul-2019 8K+ Views

& is a bitwise operator and compares each operand bitwise.It is a binary AND Operator and copies a bit to the result if it exists in both operands.Assume integer variable A holds 60 and variable B holds 13 then  (A & B) will give 12 which is 0000 1100.Whereas && is a logical AND operator and operates on boolean operands. If both the operands are true, then the condition becomes true otherwise it is false. Assume boolean variable A holds true and variable B holds false then (A && B) is false.& is to be used during bitwise operations and && is useful during logical operations.

Read More

Differences between & and && operators in Java.

Kumar Varma
Kumar Varma
Updated on 30-Jul-2019 8K+ Views

& is a bitwise operator and compares each operand bitwise.It is a binary AND Operator and copies a bit to the result if it exists in both operands.Assume integer variable A holds 60 and variable B holds 13 then  (A & B) will give 12 which is 0000 1100.Whereas && is a logical AND operator and operates on boolean operands. If both the operands are true, then the condition becomes true otherwise it is false. Assume boolean variable A holds true and variable B holds false then (A && B) is false.& is to be used during bitwise operations and && is useful during logical operations.

Read More

how to convert Object array to String array in java

Sai Nath
Sai Nath
Updated on 30-Jul-2019 5K+ Views

As list.toArray() returns an Object[], it can be converted to String array by passing the String[] as parameter. See the example below.import java.util.ArrayList; import java.util.List; public class Tester { public static void main(String[] args) { List data = new ArrayList(); data.add("A"); data.add("B"); data.add("C"); //Object[] objects = data.toArray(); String[] strObjects = data.toArray(new String[0]); for(String obj: strObjects) { System.out.println(obj); } } }OutputA B C

Read More

remove null value from a String array in Java

Jai Janardhan
Jai Janardhan
Updated on 30-Jul-2019 4K+ Views

Following program creates an array with null values. Convert it a list with not-null values only and then get the array of that list.Exampleimport java.util.ArrayList; import java.util.List; public class Tester { public static void main(String[] args) { String[] array = {"I", null, "love", null, "Java" }; List values = new ArrayList(); for(String data: array) { if(data != null) { values.add(data); } } String[] target = values.toArray(new String[values.size()]); for(String data: target) { System.out.println(data + " "); } } }OutputI love Java

Read More

How to convert List to int[] in Java?

Sreemaha
Sreemaha
Updated on 30-Jul-2019 1K+ Views

You can simply iterate through list and fill the array as shown below −import java.util.ArrayList; import java.util.List; public class Tester {    public static void main(String[] args) {       List list = new ArrayList();       list.add(new Integer(1));       list.add(new Integer(2));       list.add(new Integer(3));       list.add(new Integer(4));       int[] array = new int[list.size()];       for(int i=0;i

Read More

Java string concat() method vs "+" operator

Akshaya Akki
Akshaya Akki
Updated on 30-Jul-2019 359 Views

The notable differences between concat() method and +operator are:concat() method+operatorYou cannot concat a null value to a String using the concat() method.You can concat null value using the ‘+’ operator.Using the concat() method you can concat only two String variables.Using the ‘+’ operator you can concat multiple values.Using the concat() method you can concat only String type of arguments.Using the ‘+’ operator you can concat any type of arguments.

Read More

What is string constant pool in Java?

Jai Janardhan
Jai Janardhan
Updated on 30-Jul-2019 983 Views

When you store a String asString str1 = "Hello";directly, then JVM creates a String object with the given value in a separate block of memory known as String constant pool.And whenever we try to create another String asString str2 = "Hello";JVM verifies whether any String object with the same value exists in the String constant pool, if so, instead of creating a new object JVM assigns the reference of the existing object to the new variable.And when we store String asString str = new String("Hello");using the new keyword, a new object with the given value is created irrespective of the ...

Read More

Checking for Null or Empty or White Space Only String in Java.

Anjana
Anjana
Updated on 30-Jul-2019 2K+ Views

We can verify whether the given string is empty using the isEmpty() method of the String class. This method returns true only if length() is 0. Example import java.lang.*; public class StringDemo {     public static void main(String[] args) {         String str = "tutorialspoint";         // prints length of string         System.out.println("length of string = " + str.length());         // checks if the string is empty or not         System.out.println("is this string empty? = " + str.isEmpty());     } } Output length of string = 14 is this string empty? = false

Read More
Showing 4411–4420 of 4,498 articles
« Prev 1 440 441 442 443 444 450 Next »
Advertisements