String.isBlank()
Code Comparison
boolean blank =
str.trim().isEmpty();
// or: str.trim().length() == 0
boolean blank = str.isBlank(); // handles Unicode whitespace too
Why the modern way wins
๐
Self-documenting
isBlank() says exactly what it checks.
๐
Unicode-aware
Handles all Unicode whitespace, not just ASCII.
โก
No allocation
No intermediate trimmed string is created.
Old Approach
trim().isEmpty()
Modern Approach
isBlank()
JDK Support
String.isBlank()
Available
Widely available since JDK 11 (Sept 2018)
How it works
isBlank() returns true if the string is empty or contains only whitespace, including Unicode whitespace characters that trim() misses.
Related Documentation
Proof