String isNullOrEmpty in Java? [duplicate]
-
StringUtils.isEmpty(str)
orStringUtils.isNotEmpty(str)
-
StringUtils.isBlank(str)
orStringUtils.isNotBlank(str)
from Apache commons-lang.
The difference between empty
and blank
is : a string consisted of whitespaces only is blank
but isn't empty
.
I generally prefer using apache-commons if possible, instead of writing my own utility methods, although that is also plausible for simple ones like these.
If you are doing android development, you can use:
TextUtils.isEmpty (CharSequence str)
Added in API level 1 Returns true if the string is null or 0-length.