StringUtils.isBlank() vs 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.

From the linked documentation:

Checks if a String is whitespace, empty ("") or null.

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

For comparison StringUtils.isEmpty:

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

Warning: In java.lang.String.isBlank() and java.lang.String.isEmpty() work the same except they don't return true for null.

java.lang.String.isBlank()

java.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.

 

你可能感兴趣的:(StringUtils.isBlank() vs String.isEmpty())