StringUtils.isNotEmpty() VS StringUtils.isNotBlank()

StringUtils.isNotEmpty()

StringUtils.isNotEmpty() is used to find if the String is not empty/String is length 0 and not null.

Example:

StringUtils.isNotEmpty(null)      = false
StringUtils.isNotEmpty(“”)        = false
StringUtils.isNotEmpty(” “)       = true
StringUtils.isNotEmpty(”  lol  “) = true
StringUtils.isNotEmpty(“lol”)     = true

StringUtils.isNotBlank()

StringUtils.isNotBlank() takes it a step forward. It not only checks if the String is not empty and not null, but also checks if it is not only a whitespace string.

Example:

StringUtils.isNotBlank(null)      = false
StringUtils.isNotBlank(“”)        = false
StringUtils.isNotBlank(” “)       = false
StringUtils.isNotBlank(“str”)     = true
StringUtils.isNotBlank(”  str  “) = true

Leave a comment