map的遍历

 

JDK8推荐使用

 

map.forEach((K, V) -> {
System.out.println("Key : " + K);
System.out.println("Value : " + V);
});

 

 

 foreach推荐使用

 

for (Map.Entry<String, String> entry : map.entrySet()) {
System.out.println("Key : " + entry.getKey());
System.out.println("Value : " + entry.getValue());
}

 

 

不推荐使用

 

for (String key : map.keySet()) {
System.out.println("Key : " + key);
System.out.println("Value : " + map.get(key));
}
posted @ 2019-12-19 17:29  不死码农  阅读(155)  评论(0编辑  收藏  举报