判断集合为空方法

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

  • IDEA中怎么设置渲染文档注释
  • intellij idea如何设置java代码风格
  • VSCODE-GIT提交authentication failed处理方法
  • Windows下PyQt4的安装
  • 怎么获取配置文件的值
  • 热门搜索
    职业兴趣怎么写 剪映怎么去水印 猪肚怎么做好吃 发烧了怎么办 白菜的做法大全家常 同学用英语怎么说 保证书怎么写给老婆 雪茄怎么抽 excel求和怎么操作 炸鲜蘑的家常做法