// 创建一个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);
});
10-08
677
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)