w3resource logo


Introduction to Java Programming

Java String: isEmpty() Method

Secondary Nav

public String isEmpty()

The isEmpty() method is used to check if length() is 0 for a given string.

Java Platform: Java SE 8

Syntax :

isEmpty()

Return Value : true if length() is 0, otherwise false

Return Value Type: boolean

Example : Java String isEmpty() Method

The following example shows the usage of java String() method.

import java.lang.*;

public class StringExample {

   public static void main(String[] args) {
  
   String str1 = "javaexercises";
   System.out.println();
   // prints length of string
   System.out.println("Length of string = " + str1.length());
   
   // checks if the string is empty or not
   System.out.println("Is this string empty? = " + str1.isEmpty());
   System.out.println();
   }
}

Output:

Length of string = 13                                                          
Is this string empty? = false

Java Code Editor:







Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program