Java Program to check if a string is empty or not

Java 8Object Oriented ProgrammingProgramming

The following is our string −

String str = "";

We will check whether it is empty or not using the isEmpty() method. The result will be a boolean −

str.isEmpty()

The following is an example −

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      String str = "";
      System.out.println("String is empty: "+str.isEmpty());
   }
}

Output

String is empty: true
raja
Published on 17-Dec-2018 11:21:09
Advertisements