Map<String,Integer> map = new HashMap<>(); map.put("one",1); map.put("two",1); map.put("three",1); map.put("four",1); map.put("five",1); for(Map.Entry<String,Integer> me:map.entrySet()){ System.out.println(me.getKey() + " --> " + me.getValue()) ; }
map.forEach((key, value) -> { System.out.println(key + ":" + value); });
参考
https://www.cnblogs.com/zhaoguhong/p/7074597.html?utm_source=itdadao&utm_medium=referral