Check if String is null, empty or blank with Apache Commons StringUtils class



This example shows how to use the Apache Commons Lang to check if a string is an empty string, null or contains only white spaces. This is more convenient than writing several conditions in an if statement.

There are actually two methods that check if the string is an empty string or if it’s null, isEmpty() and isBlank(). The second method also checks if the string contains only white spaces.

Here is an example with a string that is null:

and here is an example with a string that is empty:

and here is an example with a string that contains only white spaces:







Search for more Java info on this site here:
Custom Search


Please type any questions here.