how can i replaced Key Value with value keys of a Map
I want to write a method which will take a map as parameter and replace
the keys and values of that map by values and keys. I am trying to do like
this
`public class HashMapKeyValueInterchange{
public static Map<String, String> getMyMap(ConcurrentHashMap<String,
String> m){
Map<String, String> map2 = new HashMap<String, String>();
for(Entry<String, String> e:m.entrySet()){
map2.put(e.getValue(), e.getKey());
}
return map2;
}
public static void main(String[] args) {
ConcurrentHashMap<String, String> map1 = new ConcurrentHashMap<String,
String>();
map1.put("ajay", "btech");
map1.put("manas", "mca");
map1.put("ashu", "mba");
} }`
No comments:
Post a Comment