DEV Community

taijidude
taijidude

Posted on

TIL: isBlank() String Method

Today i learned that in Java 11 there was a new String Method introduced that checks if a string is empty or just contains blanks and the same time.

So instead of this:

String toCheck = " ";
if(toCheck.trim().isEmpty()) {
...
}
Enter fullscreen mode Exit fullscreen mode

You can do this:

String toCheck = " ";
if(toCheck.isBlank()) {
...
}
Enter fullscreen mode Exit fullscreen mode

Makes the if statement a bit cleaner.

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay