判断集合为空方法
1、判断列表list为空的方法:
public static boolean isEmptyList(Collection<?> collection) {
return collection == null || collection.isEmpty();
}
Collection一个集合框架来的 也是一个集合接口 通过属性isEmpty()来判断有没有数据
2、判断Map为空的方法:
public static boolean isEmptyMap(Map<?, ?> map) {
return map == null || isEmptyList(map.keySet());
}
Map 是一个键值对映射的集合接口 通过map.keySet()方法来返回一个set再判断它是否为空
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:166
阅读量:34
阅读量:89
阅读量:105
阅读量:90