Checking if a collection is empty in Java: which is the best method?

后端 未结 11 1616
醉话见心
醉话见心 2020-12-01 01:27

I have two ways of checking if a List is empty or not

if (CollectionUtils.isNotEmpty(listName)) 

and

if (listName != null          


        
11条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-01 01:52

    isEmpty()
    
          Returns true if this list contains no elements.
    

    http://docs.oracle.com/javase/1.4.2/docs/api/java/util/List.html

提交回复
热议问题