Java 11 - String isBlank() method example

Java 11 added a few useful APIs to the commonly used String class.  String isBlank() method is one of them. In this post, we will see the usage of String isBlank() method with an example.

Check out New String APIs/Methods in Java 11 (JDK11) with Examples

isBlank() API

The isBlank() String class method returns true if the string is empty or contains only whitespace. Otherwise, it returns false:
package net.javaguides.examples;
/**
 * Java 11 (JDK11) New String APIs/Methods with Examples
 * @author Ramesh Fadatare
 *
 */
public class StringAPIInJDK11 {
    public static void main(String[] args) {

        String input = "\n\t\u2005 ";

        /**
         * The isBlank() instance method returns true if the string is empty or contains
         * only whitespace. Otherwise, it returns false
         */
        boolean result = input.isBlank();
        System.out.println(result);
    }
}
Output:
true

Reference



Comments