工具类:org.apache.commons.collections.CollectionUtils#isEmpty
/**
* Null-safe check if the specified collection is empty.
* <p>
* Null returns true.
*
* @param coll the collection to check, may be null
* @return true if empty or null
* @since Commons Collections 3.2
*/
public static boolean isEmpty(Collection coll) {
return (coll == null || coll.isEmpty());
}
判断不为空:
/**
* Null-safe check if the specified collection is not empty.
* <p>
* Null returns false.
*
* @param coll the collection to check, may be null
* @return true if non-null and non-empty
* @since Commons Collections 3.2
*/
public static boolean isNotEmpty(Collection coll) {
return !CollectionUtils.isEmpty(coll);
}
本文介绍了一个实用的工具方法,用于进行集合的空值检查。通过使用org.apache.commons.collections.CollectionUtils中的isEmpty和isNotEmpty方法,可以方便地判断集合是否为空或非空,提供了代码的健壮性和可读性。
9344

被折叠的 条评论
为什么被折叠?



