@Test
    public void test02() {
        Map<String,Integer> map = new HashMap<>();
        map.put("a", 21);
        map.put("b", 22);
        map.put("c", 23);
        Set<Entry<String,Integer>> entrySet = map.entrySet();
        for (Entry<String, Integer> entry : entrySet) {
            System.out.println(entry.getKey() + "---->" + entry.getValue());
        }
    }

如上代码,新建一个Map,然后放入K和V,最后遍历,使用JUnit5测试该方法,控制台输出效果如下:

相对高效的遍历Map的方法,其他方法效率相对较低

 

相关文章:

  • 2021-11-07
  • 2022-12-23
  • 2022-12-23
  • 2021-05-09
  • 2022-12-23
  • 2021-09-07
  • 2021-05-28
  • 2021-11-30
猜你喜欢
  • 2022-12-23
  • 2021-08-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-25
  • 2022-12-23
相关资源
相似解决方案