集合的判空一般判定方法

 

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
}

 

 

 

 

 

Logo

一站式虚拟内容创作平台,激发创意,赋能创作,进入R空间,遇见同道,让优质作品闪耀发光。​

更多推荐