List的isEmpty与==null的区别


集合的判空一般判定方法

ArrayList<Person> list = null;
System.out.println(null == list);//return true
System.out.println(list.isEmpty());// null point error
ArrayList<Person> list = new ArrayList<Person>();
System.out.println(list.isEmpty());//true
System.out.println(list==null);//false

结论:判空的顺序:

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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM