isEmpty是判断是否为空,是否为空字符串;isBlank判断字符是否为空,空格、制表符、tab
详细代码:
/***
* 判断是否为空字符串,没有判断空格
* @param str
* @return 如果为空,则返回true
*/
public static boolean isEmpty(String str) {
return str == null || str.length() == 0;
}
/***
* 判断字符是否为空,空格、制表符、tab
* @param str
* @return
*/
public static boolean isBlank(String str) {
int strLen;
if (str != null && (strLen = str.length()) != 0) {
for (int i = 0; i < strLen; ++i) {
// 判断字符是否为空格、制表符、tab
if (!Character.isWhitespace(str.charAt(i))) {
return false;
}
}
return true;
} else {
return true;
}
}