Java String isBlank() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Java 11+

Definition

In Java, isBlank() returns true if the string is empty or every character in it is whitespace, such as spaces, tabs, and line breaks. " ".isBlank() is true, while " x ".isBlank() is false.

Whitespace is decided by Character.isWhitespace, the same rule strip() uses, so s.isBlank() gives the same answer as s.strip().isEmpty() without building a new string. It is the natural check for required form fields.

isBlank() is an instance method of java.lang.String, added in Java 11. Call it on a string, as in text.isBlank(); calling it on a null reference throws NullPointerException. It only reads the text; the string itself is never changed. Requires Java 11 or newer.

Syntax

Call it with no arguments; the result is a boolean.

java
if (comment.isBlank()) {
    System.out.println("Comment is required");
}
CallWhat it does
"".isBlank()true.
" \t\n".isBlank()true: only whitespace.
" a ".isBlank()false.

Compare with isEmpty(), which is true only for length 0. Every empty string is blank, but not every blank string is empty.

Library declarations
java
public boolean isBlank();

Parameters

ParameterDescription
NoneisBlank() takes no parameters.

Return Value

Return ValueDescription
booleantrue if the string is empty or contains only whitespace code points.

Java Examples

Example 1 — isBlank() Next to isEmpty()

Four inputs show where the two checks agree and where they differ.

java
public class IsBlankVsIsEmpty {
    public static void main(String[] args) {
        String[] samples = {"", "   ", "\t\n", " x "};

        for (String s : samples) {
            System.out.println("length " + s.length() + ": isEmpty=" + s.isEmpty() + ", isBlank=" + s.isBlank());
        }
    }
}

How It Works

  1. Both true for "". A string with no characters is empty and therefore also blank.
  2. Whitespace-only text. Three spaces, or a tab plus a newline, are not empty (lengths 3 and 2) but are blank.
  3. One visible char decides. " x " contains an x, so isBlank() returns false despite the surrounding spaces.

Example 2 — Find Missing Form Fields

Mark fields that contain nothing but spaces as missing.

java
public class IsBlankForm {
    public static void main(String[] args) {
        String[][] fields = {{"name", "Ada"}, {"city", "   "}, {"email", ""}};

        for (String[] f : fields) {
            String status = f[1].isBlank() ? "missing" : "ok";
            System.out.println(f[0] + ": " + status);
        }
    }
}

How It Works

  1. Pairs of label and value. Each inner array holds a field name at index 0 and what the user typed at index 1.
  2. Spaces are not an answer. " " for city is blank, just like the empty email, so both are reported as missing.
  3. Real input passes. "Ada" contains letters, so the name field is ok.

Example 3 — Unicode Spaces: isBlank() Versus trim()

An em space and a no-break space behave differently from an ordinary space.

java
public class IsBlankUnicode {
    public static void main(String[] args) {
        String emSpace = "\u2003";
        String noBreak = "\u00A0";

        System.out.println("em space isBlank:      " + emSpace.isBlank());
        System.out.println("em space trim isEmpty: " + emSpace.trim().isEmpty());
        System.out.println("no-break isBlank:      " + noBreak.isBlank());
    }
}

How It Works

  1. The em space is whitespace. U+2003 passes Character.isWhitespace, so isBlank() returns true.
  2. trim() only knows ASCII. trim() removes chars up to U+0020; it keeps U+2003, so the trimmed string is not empty.
  3. The no-break exception. U+00A0 is deliberately excluded from Java whitespace, so a string holding only it is not blank.

Frequently Asked Questions

true if the string is empty or contains only whitespace characters, false if it contains at least one other character.
isEmpty() is true only for length 0. isBlank() is also true for strings made only of spaces, tabs, or line breaks.
Java 11. On older versions use s.trim().isEmpty() as an approximation.
No. It uses Character.isWhitespace, which excludes U+00A0, U+2007, and U+202F.
No. Calling it on null throws NullPointerException. Use s == null || s.isBlank() for optional values.

Next: isEmpty()

Check whether a string has length 0.

isEmpty() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

13 people found this page helpful