Map Foreach 输出

Map,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,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

你可能感兴趣的:(java细节)