How do I check for an empty string?
Category: commons.lang, viewed: 20992 time(s).
StringUtils.isBlank() method check to see is the string contains only whitespace characters, empty or has a null value. If these condition is true that the string considered blank.
There's also a StringUtils.isEmpty(), only these method doesn't check for whitespaces only string. For checking the oposite condition there are StringUtils.isNotBlank() and StringUtils.isNotEmpty().
Using this methods we can avoid repeating the code for checking empty string which can include more code to type then using these handy method.
The result of our program are:
var1 is blank? = true var2 is blank? = true var3 is blank? = true var4 is blank? = false var1 is not blank? = false var2 is not blank? = false var3 is not blank? = false var4 is not blank? = true var1 is empty? = true var2 is empty? = true var3 is empty? = false var4 is empty? = false var1 is not empty? = false var2 is not empty? = false var3 is not empty? = true var4 is not empty? = true
Can't find what you are looking for? Join our FORUMS and ask some questions!
Download Hundreds of Complimentary Industry Resources
Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more;
all available at no cost to you. With more than 600 complimentary offers, you'll find
plenty of titles to suit your professional interests and needs.
Click Here and Sign up today!
