java多类型非空判断、java对Object类型进行非空判断、java对常见类型进行非空判断、java验证只能是数字字母)
public static boolean isEmpty(Object object){
if(object == null){
return true;
}
if(object instanceof String){
return "".equals(object) || "null".equalsIgnoreCase(object);
}
if(object instanceof Collection){
Collection collection = (Collection)object;
return collection.size() == 0;
}
if(object instanceof Map){
Map map = (Map)object;
return map.size() == 0;
}
if(object.getClass().isArray()){
return Array.getLength(object) == 0;
}
return false;
}
public static boolean isNotEmpty(Object object){
return !isEmpty(object);
}
public static boolean isAllNotEmpty(Object ... objects){
for(Object object:objects){
if(isEmpty(object)){
return false;
}
}
return true;
}
public static boolean isAllEmpty(Object ... objects){
for(Object object:objects){
if(!isEmpty(object)){
return false;
}
}
return true;
}
public static boolean isNumberAndLetter(String s){
if(isNotEmpty(s)){
String regex = "^[0-9a-zA-z]+$";
return s.matches(regex)
}
return false;
}