How to check if String is empty in Java?

Java 8Object Oriented ProgrammingProgramming

The isEmpty() method of the String class returns true if the length of the current string is 0.


Live Demo

import java.lang.*;
public class StringDemo {
   public static void main(String[] args) {
      String str = "tutorialspoint";

      //prints length of string
      System.out.println("length of string = " + str.length());

      //checks if the string is empty or not
      System.out.println("is this string empty? = " + str.isEmpty());


length of string = 14
is this string empty? = false
Updated on 26-Feb-2020 08:24:12