Saturday 15 May 2010

replace keys in hashmap with the keys of other hashmap java -



replace keys in hashmap with the keys of other hashmap java -

i have got 2 hash maps. first is

map<string, arraylist<string>> name = new hashmap<string, arraylist<string>>();

which contains name key , city value. sec is

map<string, arraylist<string>> games = new hashmap<string, arraylist<string>>();

which contains city key , list of games played per city value.

so, want compare cities , if cities match, want assign list of games played value name key. i.e. need hash map have name key , list of games played value.

i need help here please give detailed info finish beginner java.

thanks in advance

i think first map should contain name key , city value instead of list of city.

with assumption below code work

map<string, arraylist<string>> namegamelistmap= new hashmap<string, arraylist<string>>(); iterator<string> = name.keyset().iterator(); while(it.hasnext()) { string name = it.next(); string city = name.get(name); if(games.containskey(city)) { namegamelistmap.put(name, games.get(city)); } }

java hashmap

No comments:

Post a Comment