1.判断字符串是否为null或长度为0
public static boolean isStrEmpty(String str) {
if (str == null || str.length() == 0) {
return true;
} else {
return false;
}
}
2.判断数组是否为null或者长度为0
public static <T> boolean isArrayEmpty(T[] array) {
if (getArraySize(array) == 0) {
return true;
} else {
return false;
}
}
3.获取数组的长度
public static <T> int getArraySize(T[] array) {
return array == null ? 0 : array.length;
}
4.判断List是否为null或size = 0
public static <T> boolean isListEmpty(List<T> list) {
if (getListSize(list) == 0) {
return true;
} else {
return false;
}
}
5.获取List数据的size
public static <T> int getListSize(List<T> list) {
return (list == null) ? 0 : list.size();
}
6.判断Map是否为null或size = 0
public static <K, V> boolean isMapEmpty(Map<K, V> map) {
if (getMapSize(map) == 0) {
return true;
} else {
return false;
}
}
7.获取Map数据的size
public static <K, V> int getMapSize(Map<K, V> map) {
return (map == null) ? 0 : map.size();
}
8.判断Set是否为null或size = 0
public static <E> boolean isSetEmpty(Set<E> set) {
if (getSetSize(set) == 0) {
return true;
} else {
return false;
}
}
9.获取Set数据的size
public static <E> int getSetSize(Set<E> set) {
return set == null ? 0 : set.size();
}
10.判断字符串是否为纯数字
public static boolean isNumber(String str) {
if (isStrEmpty(str)) {
return false;
}
return str.matches("[0-9]+");
}
11.判断字符串是否为纯字母
public static boolean isLetter(String str) {
if (isStrEmpty(str)) {
return false;
}
return str.matches("[a-zA-Z]+");
}
12.判断是否为邮箱格式
public static boolean isEmailAddress(String str) {
String match = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
if (isStrEmpty(str)) {
return false;
}
return str.matches(match);
}