用法
判断集合是否为空
CollectionUtils.isEmpty(null): true
CollectionUtils.isEmpty(new ArrayList()): true
CollectionUtils.isEmpty({a,b}): false
判断集合是否不为空
CollectionUtils.isNotEmpty(null): false
CollectionUtils.isNotEmpty(new ArrayList()): false
CollectionUtils.isNotEmpty({a,b}): true
public static boolean isEmpty(Collection coll) (org.apache.commons.collections.CollectionUtils)和public boolean isEmpty()(java.util.ArrayList;)的区别
代码
import org.apache.commons.collections.CollectionUtils;
import java.util.ArrayList;
public class demo {
public static void main(String[]args) {
ArrayList arrayList1 = new ArrayList();
ArrayList arrayList2 = null;
System.out.println(CollectionUtils.isEmpty(arrayList1));
System.out.println(arrayList1.isEmpty());
System.out.println(CollectionUtils.isEmpty(arrayList2));
System.out.println(arrayList2.isEmpty());
}
}
结果
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/480aa8648aeae154fa97d400da8e8609.png)