//如果object为null,则设置为defaultValue
ObjectUtils.defaultIfNull(object, defaultValue);

//判断集合是否为null
List<String> list=new ArrayList<String>();
System.out.println(list.isEmpty()); //true
System.out.println(list.size()); //0

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

Set<String> set=new HashSet<String>();
System.out.println(set.isEmpty()); //true
System.out.println(set.size()); //0

Map<String, String> map=new HashMap<String, String>();
System.out.println(map.isEmpty()); //true
System.out.println(map.size()); //0

方法一(数据量大,效率低):
if(list!=null && list.size()>0){
}

方法二(数据量大,效率高):
if(list!=null && !list.isEmpty()){
}

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄