java hashmap key iteration

前端 未结 7 650
谎友^
谎友^ 2020-12-29 06:46

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?

相关标签:
7条回答
  • 2020-12-29 07:19

    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.

    0 讨论(0)
提交回复
热议问题