TextUtils.isEmpty()怎么用

这个方法的源码是这样的:

/**
 * Returns true if the string is null or 0-length.
 * @param str the string to be examined
 * @return true if str is null or zero length
 */
public static boolean isEmpty(@Nullable CharSequence str) {
    return str == null || str.length() == 0;
}

可以用来判断非null或者“”,但是如果是“ ”的话,需要先将字符串str.replace(" ", ""); 去掉所有空格,包括首尾、中间。

你可能感兴趣的:(android)