判断集合为空方法

时间:2026-02-14 15:57:51

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再判断它是否为空

© 2026 五度知识库
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com