Best structure for list of key-value (integer, string) to be shuffled

后端 未结 5 2069
抹茶落季
抹茶落季 2021-02-06 03:37

I need to implement a structure in Java that is a key-value list (of types Integer-String) and I want to shuffle it.

Basically, I would like to do something like that.

5条回答
  •  梦毁少年i
    2021-02-06 04:14

    You could keep a separate List of the keyvalues, shuffle that and use it to access the HashMap.

    List keys = new ArrayList(map.keySet());
    Collections.shuffle(keys);
    for(Integer i : keys)
        map.get(i);     // Gets the values in the shuffled order
    

提交回复
热议问题