public static void main(String[] args) {
        Map<String, String> map = new HashMap<String, String>();
        System.out.println("map为空:" + map.isEmpty());
        //加入元素
        map.put("1", "1");
        System.out.println("map为空:" + map.isEmpty());
    }
这里是用isEmpty()方法来做判断,其实和map.size()也没差,可以看下isEmpty()方法的源码:

 public boolean isEmpty() {
        return size == 0;
    }
1
2
3
其实就是把map的size和0做个判断,返回false和true结果。
map为空的问题
Map<String, Object> resultMap = new HashMap<>();

resultMap!=null

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2022-02-24
  • 2021-12-04
  • 2021-05-22
猜你喜欢
  • 2022-01-18
  • 2021-12-10
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案