map的遍历

Posted leeego-123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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));
}

以上是关于map的遍历的主要内容,如果未能解决你的问题,请参考以下文章