1. Detailed explanation of isEmpty method source code
public static boolean isEmpty(CharSequence cs){
return (cs == null) || (() == 0);
}
Source code analysis: The above method shows that true is returned only when the string is not null or non-empty string (""); the isNotEmpty method is the opposite of isEmpty;
See the following examples on the official website:
StringUtils.isEmpty(null) = true
StringUtils.isEmpty("") = true
StringUtils.isEmpty(" ") = false
StringUtils.isEmpty("bob") = false
StringUtils.isEmpty(" bob ") = false
2. Detailed explanation of isBlank method source code
public static boolean isBlank(CharSequence cs)
{
int strLen;
if ((cs == null) || ((strLen = ()) == 0))
return true;
int strLen;
for (int i = 0; i < strLen; i++) {
if (!((i))) {
return false;
}
}
return true;
}
Source code analysis: First, when the parameters passed in are null or empty strings, true will be returned. Next, we use the method to determine whether all characters are whitespace characters (spaces, tab keys, newlines). If so, false will be returned, otherwise true will be returned; the isNotBlank method is the opposite of the isBlank method;
Take a look at the examples from the official website:
(null) = true
("") = true
(" ") = true
("bob") = false
(" bob ") = false
3. isAnyBlank source code
public static boolean isAnyBlank(CharSequence... css)
{
if ((css)) {
return false;
}
for (CharSequence cs : css) {
if (isBlank(cs)) {
return true;
}
}
return false;
}
Source code analysis: First, whether the parameter array is empty, if it is empty, return false, if the array is not empty, determine whether each string in the array is blank, and if there is a blank, it returns true; isNoneBlank identifies that no element in the array is a blank, which is the opposite of isAnyBlank;
4. isAllBlank source code analysis
public static boolean isAllBlank(CharSequence... css)
{
if ((css)) {
return true;
}
for (CharSequence cs : css) {
if (isNotBlank(cs)) {
return false;
}
}
return true;
Source code analysis: First, determine whether the parameter array is empty. If it is returned true, otherwise if there is a non-whitespace element in the array, it will return false;