判断集合为空方法

 时间:2026-04-23 14:05:01

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的安装
  • 怎么获取配置文件的值
  • 热门搜索
    苹果手机怎么发彩信 炖牛肉怎么做好吃 安阳工学院怎么样 淘宝怎么评论 吉他简谱怎么看 水银温度计怎么看图解 sofa怎么读 食指麻木是怎么回事 鱼鳞病怎么治 我们怎么了