Java String isBlank() Method Tutorial

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

What is Java String isBlank() Method?

The Java String isBlank() method is used to check a string value and see if it’s empty or contains only white spaces. In either way, the result is true. But if the target string contains a value other than a white space, the result will be false because basically that string contains something and is not blank.

Java isBlank() Method Syntax:

public boolean isBlank()

isBlank() Method Parameters:

The method does not take an argument.

isBlank() Method Return Value:

The return value of this method is a Boolean.

If the target string value is empty or contains only white spaces, the result of the method will be true. Otherwise it is false.

isBlank() Method Exceptions:

The method does not throw an exception.

Example: using String isBlank() method

public class Main {

   public static void main(String[] args){

      String noEmpty = "None Empty String";
      String empty = "              ";




As you can see, the first string value contains only white spaces and so calling the `isBlank()` method on this string returned the value true. But for the second string value, because it is not a blank one, the result is false.


Top Technologies