java - Printing out a HashMap using an Another HashMap's key as values -
if have hashmap such
{opst=post pots stop spot tops opts, art=rat tar art, glos=slog, gopr=gorp, fgor=frog, aprt=trap tarp part, dgo=dog god, act=act cat tac, fglo=flog golf}
and hashmap such as
{opst=otsp, art=atr, fgor=grof, aprt=arpt, dgo=gdo, act=atc}
how use second hashmap key print out like...
arpt part tarp trap atc act cat tac atr art rat tar gdo dog god grof frog otsp opts post pots spot stop tops
assuming first hashmap
called firstmap
, second secondmap
, navigate through keys of secondmap
print values stored on first map. here's code sample:
for (string secondmapkey : secondmap.keyset()) { system.out.println(firstmap.get(secondmapkey)); }
another option may iterating through entries of secondmap
of second map , keys (in case need value of secondmap
along key):
for (map.entry<string, string> entry : secondmap.entryset()) { system.out.println(firstmap.get(entry.getkey()) + " " + entry.getvalue()); }
Comments
Post a Comment