Oct 31, 2018

https://stackoverflow.com/questions/23419087/stringutils-isblank-vs-string-isempty

Is a difference between the two (org.apache.commons.lang3.StringUtils.isBlankandjava.lang.String.isEmpty)?

StringUtils.isBlank()checks that each character of the string is a whitespace character (or that the string is empty or that it's null). This is totally different than just checking if the string is empty.

eg:

StringUtils.isBlank:

StringUtils.isBlank(null)   = true
StringUtils.isBlank("")     = true
StringUtils.isBlank(" ")    = true
StringUtils.isBlank("bob")  = false
StringUtils.isBlank(" bob") = false

StringUtils.isEmpty:

StringUtils.isEmpty(null)   = true
StringUtils.isEmpty("")     = true
StringUtils.isEmpty(" ")    = false
StringUtils.isEmpty("bob")  = false
StringUtils.isEmpty(" bob") = false

StringUtils.isEmpty checks for null

StringUtils.isBlank checks if text contains only white space char(s).

Last updated

Was this helpful?