public class StringUtils {
private StringUtils() {
}
public static boolean isBlank(String str) {
return (str == null || str.trim().length() == 0);
}
/**
* 判断给定字符串是否空白串。 空白串是指由空格、制表符、回车符、换行符组成的字符串 若输入字符串为null或空字符串,返回true
*
* @param input
* @return boolean
*/
public static boolean isEmpty(String input) {
if (input == null || "".equals(input))
return true;
for (int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
if (c != ' ' && c != '\t' && c != '\r' && c != '\n') {
return false;
}
}
return true;
}
/**
* 判断str null,"","null" 均视为空.
*
* @param str 字符
* @return 结果 boolean
*/
public static boolean isNotEmpty(String str) {
boolean bool = true;
if (str == null || "null".equals(str) || "".equals(str)) {
bool = false;
} else {
bool = true;
}
return bool;
}
/**
* 检测String是否全是中文
*
* @param name
* @return
*/
public static boolean checkNameChese(String name) {
boolean res = true;
char[] cTemp = name.toCharArray();
for (int i = 0; i < name.length(); i++) {
if (!isChinese(cTemp[i])) {
res = false;
break;
}
}
return res;
}
/**
* 判断给定List是否为空。 若输入字符串为null或空字符串,返回true
*
* @param list
* @return boolean
*/
public static boolean isEmpty(List<?> list) {
if (list == null)
return true;
if (list.size() <= 0) {
return true;
}
return false;
}
/**
* 去除字符串中的空格、回车、换行符、制表符
*
* @param str
* @return
*/
public static String replaceBlank(String str) {
String dest = "";
if (str != null) {
Pattern p = Pattern.compile("\\s*|\t|\r|\n");
Matcher m = p.matcher(str);
dest = m.replaceAll("");
}
return dest;
}
}
字符串或数组的处理和校验
最新推荐文章于 2024-08-06 10:22:43 发布