String isEmpty()

In recent post we have read about String class in java. In this post we will learn String isEmpty() and see how does it work behind.

String isEmpty()

The string isEmpty() used to check whether the current string is empty or not. This method is widely used in java because before performing any operation we check the string is empty or not. The String isEmpty() method works based on the length of the string, It returns true if the length of the string is greater than 0 otherwise it returns false.

stringName.isEmpty()

stringName: The name of string in which you want to check whether it is empty or not.

class ExampleOfContains
 {  
	 public static void main(String args[])
	 {    
		String name = "JAVA GOAL";  			 
		boolean isStringEmpty =  name.isEmpty();
		System.out.println("Is String is empty = "+ (isStringEmpty));
		 
		String name2 = "";
		boolean isEmptyString =  name2.isEmpty();
		System.out.println("Is String is empty = "+ (isEmptyString));
	}
}  

Output: Is String is empty = false
Is String is empty = true

Leave a Comment