Check whether a string is Empty in Java

isEmpty() method of String class can be used to check whether a string is empty.

The method returns true if the string is empty and returns false if the string is not empty.


Example 1

class EmptyTest{

public static void main(String args[]){

String string="";

boolean isempty=string.isEmpty();

System.out.println(isempty);

}

}

Output 1

true


Example 2

class StringTest{

public static void main(String args[]){

String str="Hi! How are you ?";

boolean isempty=str.isEmpty();

System.out.println(isempty);

}

}

Output 2

false