List的isEmpty与==null的区别

来源:互联网 发布:电话名单软件 编辑:程序博客网 时间:2024/06/05 20:30

集合的判空一般判定方法

<span style="white-space:pre"></span>ArrayList<Person> list = null;System.out.println(null == list);//return trueSystem.out.println(list.isEmpty());// null point error

ArrayList<Person> list = new ArrayList<Person>();System.out.println(list.isEmpty());//trueSystem.out.println(list==null);//false

结论:判空的顺序:

if(null != list && !list.isEmpty()){//code}


0 0