Sunday, 15 May 2011

Inverted HashMap in Java whit frequency -



Inverted HashMap in Java whit frequency -

i have hashmap<string, linkedlist<integer>> , want create hashmapinverted<linkedlist<integer>, set<string>> contains in keys lists, values of first map, , values set of strings have same list in first map.

how can this?

you can do:

map<linkedlist<integer>, set<string>> mapinverted = new hashmap<>(mymap.size()); for(entry<<string, linkedlist<integer>> entry : mymap.entryset()) { string key = entry.getkey(); linkedlist<integer> list = entry.getvalue(); set<string> strings = mapinverted.get(list); if(strings == null) { // list has not been set in map strings = new hashset<string>(); // create new set mapinverted.put(list, strings); // set list , new set } strings.add(key); }

java

No comments:

Post a Comment