Join our newsletter for the latest updates.

Java String isEmpty()

The Java String isEmpty() method checks whether the string is empty or not.

The syntax of the string isEmpty() method is:

string.isEmpty()

Here, string is an object of the String class.


isEmpty() Parameters

The isEmpty() method does not take any parameters.


isEmpty() Return Value

  • returns true if the string is empty (length is 0)
  • returns false if the string is not empty

Example: Java String isEmpty()

class Main {
  public static void main(String[] args) {

    String str1 = "Java Programming";
    String str2 = "";

    System.out.println(str1.isEmpty()); // false
    System.out.println(str2.isEmpty()); // true

  }
}

Note: A non-initialized string is not an empty string. If you use isEmpty() on a string that is not initialized, you will get an error.