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...!!! Share on X

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...!!! Share on X

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

Other Useful References:

Author

  • Deepak Verma

    Deepak Verma is a Test Automation Consultant and Software development Engineer for more than 10 years. His mission is to help you become an In-demand full stack automation tester. He is also the founder of Techndeck, a blog and online coaching platform dedicated to helping you succeed with all the automation basics to advanced testing automation tricks.

    http://Techndeck.com deepak.rkgit@gmail.com Verma Deepak