Java Program to check if a string is empty or not


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

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 27-Jun-2020

226 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements