TextUtils.isEmpty()方法代码实现
public static boolean isEmpty(@Nullable CharSequence str) {
return str == null || str.length() == 0;
}
代码会进行str的null判断;
String.isEmpty()代码实现
public boolean isEmpty() {
// Android-changed: Get length from count field rather than value array (see above).
// Empty string has {@code count == 0} with or without string compression enabled.
// return value.length == 0;
return count == 0;
}
仅进行长度判断,未进行null判断,如果字符串为null,会直接报空指针。