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

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

    A solution is already selected. However, I post this solution for those who want to use an alternative approach:

    // use LinkedHashMap if you want to read values from the hashmap in the same order as you put them into it
    private ArrayList getMapValueAt(LinkedHashMap> hashMap, int index)
    {
        Map.Entry> entry = (Map.Entry>) hashMap.entrySet().toArray()[index];
        return entry.getValue();
    }
    

提交回复
热议问题