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

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.


You can use HashMap<String,List<String>> if you need to keep few values in one key.

Example

HashMap<String,List<String>> map=new HashMap<String,List<String>>();

//to put data firs time
String country="USA";
//create list for cities
List<String> cityList=new ArrayList<String>();
//then fill list
cityList.add("New York");
cityList.add("Los Angeles ");
cityList.add("Chicago");

//lets put this data to map
map.put(country, cityList);

//same thind with other data
country="Pakistan";
cityList=new ArrayList<String>();
cityList.add("Lahore");
cityList.add("Karachi");
map.put(country, cityList);

//now lets check what is in map
System.out.println(map);

//to add city in USA
//you need to get List of cities and add new one 
map.get("USA").add("Washington");

//to get all values from USA
System.out.println("city in USA:");
List<String> tmp=map.get("USA");
for (String city:tmp)
    System.out.println(city);