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

后端 未结 10 1374
鱼传尺愫
鱼传尺愫 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:21

    HashMaps don't keep your key/value pairs in a specific order. They are ordered based on the hash that each key's returns from its Object.hashCode() method. You can however iterate over the set of key/value pairs using an iterator with:

    for (String key : hashmap.keySet()) 
    {
        for (list : hashmap.get(key))
        {
            //list.toString()
        }
    }
    

提交回复
热议问题