java hashmap key iteration(java hashmap键迭代)
问题描述
有没有办法遍历 java Hashmap 并打印出作为 Hashmap 一部分的每个键的所有值?
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 循环,使用 Map.keySet()
用于迭代键,Map.values()
用于迭代值和 Map.entrySet()
用于迭代键/值对.
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键迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:java hashmap键迭代


基础教程推荐
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- Struts2 URL 无法访问 2022-01-01