nonEmpty Returns true for string with only space


Hi Team,

" ".nonEmpty ==> Returns true . Expected out is it should return false. I don’t want to use ‘trim’ over head.

I could see in org.apache.commons.lang3.StringUtils.isNonEmplty(" ") returns false.

Is there any specific reason for keeping it to true.


true is correct. nonEmpty is a generic method on every collection and a string with a space is not an empty string.

To avoid trim you might use for instance this: " ".forall(_.isWhitespace)


I think you will also find that you are mistaken about StringUtils. From its JavaDoc:

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