判断集合为空方法

 时间: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的安装
  • 怎么获取配置文件的值
  • 热门搜索
    借呗怎么借钱 海参粥的家常做法 拼音怎么打出来 止血方法 米饭配什么菜好吃 笑话大全 爆笑简短 萝卜怎么做好吃 怎么炖排骨好吃 红烧排骨的家常做法 怕冷怎么调理