package brilliance.znjt.serviceratingservice.utils;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class xx {
/**
* 对象是否为空
* @param obj String,List,Map,Object[],int[],long[]
* @return
*/
@SuppressWarnings("rawtypes")
public static boolean isEmpty(Object o) {
if (o == null) {
return true;
}
if (o instanceof String) {
if (o.toString().trim().equals("")||o.toString().trim().equals("null")) {
return true;
}
} else if (o instanceof List) {
if (((List) o).size() == 0) {
return true;
}
} else if (o instanceof Map) {
if (((Map) o).size() == 0) {
return true;
}
} else if (o instanceof Set) {
if (((Set) o).size() == 0) {
return true;
}
} else if (o instanceof Object[]) {
if (((Object[]) o).length == 0) {
return true;
}
} else if (o instanceof int[]) {
if (((int[]) o).length == 0) {
return true;
}
} else if (o instanceof long[]) {
if (((long[]) o).length == 0) {
return true;
}
} else if(o instanceof Integer) {
if (o.toString().trim().equals("0")) {
return true;
}
}
return false;
}
/**
* 对象组中是否存在 Empty Object
* @para
java判断是否为空工具类判断为空
最新推荐文章于 2024-08-16 22:34:20 发布
本文探讨了在Java中如何创建一个高效的工具类,用于检查对象、字符串、集合及数组是否为空,提供了静态方法示例,帮助开发者优化代码中的空值处理,提升程序稳定性。
摘要由CSDN通过智能技术生成