Java String isempty() method with Example

In the last tutorial, we have learned how to compare two strings in Java. In this tutorial, we will learn how to check the string is empty or not. The isEmpty() method of the String class is used to check whether the string is empty or not. If the string is empty then the isEmpty() method returns true otherwise it returns false. In other words, we can say that this method returns true if the string length is 0.

Syntax: The syntax of the isEmpty() of string class is given below:

public boolean isEmpty() 




Example of String isEmpty() method in Java:

class StringEmpty{
 public static void main(String args[]){
  // Non-empty string.
  String str1 = "Javastudypoint";
  //empty string.
  String str2 = "";
  //returns false.
  System.out.println(str1.isEmpty());
  //retuens true.
  System.out.println(str2.isEmpty());
 }
}

Output:
Java String isempty() method with Example

Java String isempty() method with Example Java String isempty() method with Example Reviewed by Prashant Srivastava on January 03, 2020 Rating: 5

No comments:

Powered by Blogger.