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
}

 

posted @ 2020-07-02 11:31  Wjhsmart  阅读(954)  评论(0编辑  收藏  举报