Androider Androider - 27 days ago 15
Java Question

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

HashMap roleRightsID = new HashMap();

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

Answer

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.