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 :


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";
   // 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());


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

Java Code Editor:

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