How to check blank or empty string in Java 11 using isBlank

In this post, we will learn “How to check blank or empty string in Java 11?”. Java 11 introduced a new method called isBlank to determine if a given string is blank or empty.

Here, we are going to learn following things:

  1. What is isBlank() method?
  2. How to use it?
  3. How is it different from isEmpty() method?

Check blank or empty string in Java 11...!!! Click To Tweet

 

Let’s Begin,

1. What is isBlank() method?

isBlank() is a boolean method of String class.

This method returns true if the string is empty or contains only white space, otherwise false.

isBlank_Java11_Signature_Techndeck

 

2. How to use it?

 

Output:

 

2. How is it different from isEmpty() method?

isEmpty() is a boolean method of String class similar to isBlank method and they both performs the same task of checking whether the string is blank or empty. BUT, there is a difference between the two.

isEmpty() method returns true if, and only if, length of the string is 0. while on the other hand, isBlank method checks for non-white characters only, it doesn’t check the string length.

Let’s see several examples of isBlank vs isEmpty usage and notice the differences.

 

Output:

 

Check blank or empty string in Java 11...!!! Click To Tweet

Do you like this Post? – then check my other helpful posts:

Other Useful References:

 

Related Posts:

[wcp-carousel id=”5342″]

Promotional Content:

Loading RSS Feed

Leave a Reply

Your email address will not be published.Required fields are marked *

Facebook Twitter Instagram YouTube