java hashmap key iteration

前端 未结 7 695
谎友^
谎友^ 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:01

    for (Map.Entry e : map.entrySet())
    {
        T key = e.getKey();
        U value = e.getValue();
        .
        .
        .
    }
    

    In addition, if you use a LinkedHashMap as the implementation, you'll iterate in the order the key/value pairs were inserted. If that's not important, use a HashMap.

提交回复
热议问题