java hashmap密钥迭代 [英] java hashmap key iteration

查看:113
本文介绍了java hashmap密钥迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么方法可以迭代Java HashMap并为Hashmap中的每个键打印出所有的值?

div>

使用 for-each循环 ,请使用 Map.keySet() 用于迭代键, Map.values() 用于迭代值和 Map.entrySet()

请注意,所有这些都是用于获取它们的地图的直接视图,因此您可以对其进行任何修改到三者中的任何一个或地图本身也会反映给所有其他人。


Is there any way to iterate through a java Hashmap and print out all the values for every key that is a part of the Hashmap?

解决方案

With for-each loop, use Map.keySet() for iterating keys, Map.values() for iterating values and Map.entrySet() for iterating key/value pairs.

Note that all these are direct views to the map that was used to acquire them so any modification you make to any of the three or the map itself will reflect to all the others too.

这篇关于java hashmap密钥迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆