Using the Apache Commons Lang library, you can use StringUtils.isEmpty()to check if a string is empty ("") or zero, and StringUtils.isBlank()to check if a string is whitespace, empty ("") or zero.
Please note the differences:
IsEmpty ()
StringUtils.isEmpty(null) = true
StringUtils.isEmpty("") = true
StringUtils.isEmpty(" ") = false
StringUtils.isEmpty("bob") = false
StringUtils.isEmpty(" bob ") = false
ISBLANK ()
StringUtils.isBlank(null) = true
StringUtils.isBlank("") = true
StringUtils.isBlank(" ") = true
StringUtils.isBlank("bob") = false
StringUtils.isBlank(" bob ") = false
source
share