I have a map containing keys which are album names and the values are sets of songs on those albums. I want to print the contents and here is my code:
public void printMap() {
Set<String> albumKeys = this.albumMap.keySet();
for (String eachSong : this.albumMap.keySet()) {
System.out.println("The tracks on " + albumKeys + "are: " + albumMap.get(eachSong));
}
}
The output is:
The tracks on [Genesis, The Dark Side of the Moon]are: [Home by the Sea, Illegal Alien, It's Gonna Get Better, Just a Job to Do, Mama, Second Home by the Sea, Silver Rainbow, Taking It All Too Hard, That's All] The tracks on [Genesis, The Dark Side of the Moon]are: [Any Colour You Like, Brain Damage, Eclipse, Money, On the Run, Speak to Me, The Great Gig in the Sky, Us and Them]
As you can see both the album names are printed twice each time. The asterisks indicate the name that should not be printed.
Any help would be appreciated.