CKTIS / Java
String.isBlank — checking empty or whitespace-only text
String.isBlank checks whether a string is empty or contains only whitespace as defined by Character.isWhitespace(int). It returns boolean and has been available since Java 11.
Version: Java SE 21; repository runtime, production runtime not attested
Syntax
public boolean isBlank()
// Usage: text.isBlank()String.isBlank is an instance method called as text.isBlank(). It returns true for an empty string or one containing only whitespace; otherwise, it returns false. Available since Java 11, it is described here for Java SE 21.
Whitespace follows Character.isWhitespace(int). This includes tabs, newlines and U+2003, but excludes the non-breaking space U+00A0. Visually empty text therefore does not always produce true.
isEmpty() checks only for zero length. trim().isEmpty() is not equivalent to isBlank(): trim() removes leading and trailing characters with codes no greater than U+0020. Calling isBlank() on null causes NullPointerException; if null should mean missing content, use text == null || text.isBlank().
Examples
public class Main {
public static void main(String[] args) {
String[] values = {"", " \t\n", "Java", "\u2003", "\u00A0"};
for (String value : values) {
System.out.println(value.isBlank());
}
}
}Result
true true false true false
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.