Java HashMap: How to get a key and value by index?

后端 未结 10 1334
鱼传尺愫
鱼传尺愫 2020-12-28 12:54

I am trying to use a HashMap to map a unique string to a string ArrayList like this:

HashMap>

Basical

10条回答
  •  隐瞒了意图╮
    2020-12-28 13:35

    You can do:

    for(String key: hashMap.keySet()){
        for(String value: hashMap.get(key)) {
            // use the value here
        }
    }
    

    This will iterate over every key, and then every value of the list associated with each key.

提交回复
热议问题