I have a map like this
Map map=new HashMap();//HashMap key random order.
map.put(\"a\",10);
map.put(\"a\",20);
map.put(\"a\",30);
map.put(\"b\",10);
System.
Have you checked out Guava Multimaps ?
A collection similar to a Map, but which may associate multiple values with a single key. If you call put(K, V) twice, with the same key but different values, the multimap contains mappings from the key to both values.
If you really want to use standard collections (as suggested below), you'll have to store a collection per key e.g.
map = new HashMap>();
Note that the first time you enter a new key, you'll have to create the new collection (List
, Set
etc.) before adding the first value.