可把此方法添加到工具类
public static boolean isEmpty(Object obj) {
if (obj== null) {
return true;
}
if ((obj instanceof String)) {
return ((String)obj).trim().equals("");
} else if (obj instanceof Map) {
return ((Map)obj).isEmpty();
} else if (obj instanceof Object[]) {
Object[] object = (Object[])obj;
if (object.length == 0) {
return true;
}
} else if (obj instanceof Collection) {
return ((Collection)obj).isEmpty();
} else if (obj instanceof CharSequence) {
return ((CharSequence)obj).length() == 0;
}
return false;
}
测试代码:
测试结果:



