// 创建一个Map
Map<String, Object> map= new HashMap<>();
infoMap.put("a", "a");
infoMap.put("b", "b");
infoMap.put("c", "c");
// 传统的Map迭代方式
for (Map.Entry<String, Object> entry : map.entrySet()) {
System.out.println(entry.getKey() + ":" + entry.getValue());
}
// JDK8的迭代方式
map.forEach((key, value) -> {
System.out.println(key + ":" + value);
});
标签:map,Map,System,infoMap,forEach,使用,put,entry
From: https://blog.51cto.com/u_16111396/6458180