字符串的空:有两种情况一种是null,一种是空串("");
写一个判断字符串不为空的方法:
hasLength(String s);
写一个判断字符串为空的方法:
isBlank(String s);
/**
* 字符串工具类
*
*/
public class StringUtil {
/**
* 判断字符串是否不为空
* @param str 待判断的字符串
* @return 若不为空返回true,若为空返回false
*/
public static boolean hasLength(String str){
return str!=null && !"".equals(str);
}
/**
* 判断一个字符串是否为空
* @param str 待判断的字符串
* @return 若为空返回true, 若不为空返回false
*/
public static boolean isBlank(String str){
return !hasLength(str);
}
}