12
Dec
Method to check if a string is empty or not: String.isEmpty();
public class Main {
public static void main(String[] args) {
String string1="Hello Java";
String string2="";
boolean str1=string1.isEmpty(); //expected: should be false
boolean str2=string2.isEmpty(); //expected: should be true
System.out.println(str1);
System.out.println(str2);
}
}
Output:
false
true
Leave a Reply