Map遍历方式
1. for-each + entrySet()
for (Map.Entry<String, Integer> entry : map1.entrySet()) {
System.out.print("key = " + entry.getKey());
System.out.println(", value = " + entry.getValue());
}
2. lambda表达式
map.forEach((key, value)->{
System.out.print("key = " + key);
System.out.println(", value = " + value);
});
3. stream流
map.entrySet().stream().forEach((Map.Entry<String, Integer> entry) -> {
System.out.print("key = " + entry.getKey());
System.out.println(", value = " + entry.getValue());
});
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果