Java.lang.String.isEmpty() Method
Advertisements
Description
The java.lang.String.isEmpty() method returns true only if length() is 0.
Declaration
Following is the declaration for java.lang.String.isEmpty() method
public boolean isEmpty()
Parameters
NA
Return Value
This method returns true if length() is 0, else false.
Exception
NA
Example
The following example shows the usage of java.lang.String.isEmpty() method.
package com.tutorialspoint;
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());
}
}
Let us compile and run the above program, this will produce the following result:
length of string = 14 is this string empty? = false