Is there any data structure similar to HashMap where I can add duplicate keys

hashmap, java, key-value

Solution

What you need is called a multimap, but it is does not exist in standard Java. It can be simulated with a `Map<String, List<String>>` in your case.

You can find an example here: http://docs.oracle.com/javase/tutorial/collections/interfaces/map.html, in the Multimaps section.

There is also a MultiMap in the Apache Commons Collections that you could use if you do not want to reuse the previous example.

Problem

``` HashMap<String, String> roleRightsID = new HashMap<String, String>(); ``` is there any data structure similar to HashMap where I can add duplicated keys For Example ``` USA, New York USA, Los Angeles USA, Chicago Pakistan, Lahore Pakistan, Karachi ``` etc

Original source