Skip to content
Related Articles
Open in App
Not now

Related Articles

Java String isEmpty() method with example

Improve Article
Save Article
  • Difficulty Level : Basic
  • Last Updated : 04 Dec, 2018
Improve Article
Save Article

Java.lang.String.isEmpty() String method checks whether a String is empty or not. This method returns true if the given string is empty, else it returns false. The isEmpty() method of String class is included in java string since JDK 1.6. In other words, you can say that this method returns true if the length of the string is 0.

Input String1 : Hello_Gfg
Input String2 :
Output for String1 : false
Output for String2 : true


public boolean isEmpty()
Returns : true if the length of the string is 0.

// Java program to demonstrate working of 
// isEmpty() method
class Gfg {
    public static void main(String args[])
        // non-empty string
        String str1 = "Hello_Gfg";
        // empty string
        String str2 = "";
        // prints false
        // prints true


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!