I use HashMap<String, ArrayList<String>>
in Java.
When input value is comes,
For example, input value is [1, "stack"]
, [2, "over"]
, [1, "flow"]
.....
I want to enter value [1, ["stack", "flow"]]
, [2, "over"]
in HashMap.
But key value is duplicate. So, HashMap was overwrite.
So, What can I do?
Try a Guava Multimap:
Call
get
on theMap
. If it returns aList
(Set
may be more appropriate) add to that. If it returnsnull
, create a collection, add the value, put it in the map.Better, use some third-party multimap.