Syntax error Java String isEmpty() method example.

Java String isEmpty() method example.



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

Example

 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());
   }
}

Output

length of string = 14
is this string empty? = false
Updated on: 2019-07-30T22:30:21+05:30

183 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements