部分源代码:
public static boolean hasText(@Nullable CharSequence str) {
return (str != null && str.length() > 0 && containsText(str));
}
//字符串不为null,str.isEmpty非true即false 三者都为true返回true否则返回false
public static boolean hasText(@Nullable String str) {
return (str != null && !str.isEmpty() && containsText(str));
}
//str.isEmpty()方法
@Override
public boolean isEmpty() {
return value.length == 0;
}
//判断空字符串 底层通过ASCII码值结合16进制进行判断 自行查看
private static boolean containsText(CharSequence str) {
int strLen = str.length();
for (int i = 0; i < strLen; i++) {
if (!Character.isWhitespace(str.charAt(i))) {
return true;
}
}
return false;
}
案例:
执行结果: