美文网首页
Java(判断List、Map、Set是否为空及效率比较)201

Java(判断List、Map、Set是否为空及效率比较)201

作者: 一瓶百无聊赖 | 来源:发表于2018-07-10 15:33 被阅读0次

Java高级个人笔记(判断List、Map、Set是否为空及效率比较)

//判断集合是否为null

List list=new ArrayList();

System.out.println(list.isEmpty()); //true

System.out.println(list.size());//0

Set set=newHashSet();

System.out.println(set.isEmpty()); //true

System.out.println(set.size());//0

Map map=newHashMap();

System.out.println(map.isEmpty()); //true

System.out.println(map.size());//0

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

}

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

}

做项目查询需要用到的知识!!!!!!!!!!!!!

相关文章

网友评论

      本文标题:Java(判断List、Map、Set是否为空及效率比较)201

      本文链接:https://www.haomeiwen.com/subject/bhzfpftx.html