Java String isEmpty() Method Tutorial

In this section, we will learn what the String isEmpty() method is and how to use it in Java.

What is Java String isEmpty() Method?

The Java String isEmpty() method is used to check the target string value and see if it is empty or not.

Java isEmpty() Method Syntax:

public boolean isEmpty()

isEmpty() Method Parameters:

The method does not take an argument.

isEmpty() Method Return Value:

The return value of this method is a Boolean value.

If the target string has a character in it, the returned value of calling this method will be `false`. Otherwise, if there’s no character (not even a white-space) in the target string, the result will be `true`.

isEmpty() Method Exceptions:

This method does not throw an exception.

Example: using String isEmpty() method

public class Simple {

    public static void main(String[] args)  {
        String s1 = "Hello";
        String s2 = " ";
        String s3 = "";
        System.out.println(s1.isEmpty());
        System.out.println(s2.isEmpty());
        System.out.println(s3.isEmpty());
    }
}

Output:

false

false

true

Facebook
Twitter
Pinterest
LinkedIn

Top Technologies