Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Mohit Ladia
4,140 PointsJava
Q.can someone help me with this code? private Map<String , List<Song>> byArtist(){ Map<String , List<Song>> byArtist = new HashMap<>(); for( Song song : mSongs) { List<Song> artistSongs = byArtist.get(song.getArtist()); if(artistSongs == null){ artistSongs = new ArrayList<>(); byArtist.put(song.getArtist(),artistSongs); } artistSongs.add(song); } return byArtist; } public Set<String> getArtist() { return byArtist().keySet(); } public List<Song> getSongForArtist(String artistName){ return byArtist().get(artistName); }
Gavin Ralston
28,770 Pointsprivate Map < String, List < Song >>
byArtist() {
Map < String, List < Song >> byArtist = new HashMap < > ();
for (Song song: mSongs) {
List < Song > artistSongs = byArtist.get(song.getArtist());
if (artistSongs == null) {
artistSongs = new ArrayList < > ();
byArtist.put(song.getArtist(), artistSongs);
}
artistSongs.add(song);
}
return byArtist;
}
public Set < String > getArtist() {
return byArtist().keySet();
}
public List < Song > getSongForArtist(String artistName) {
return byArtist().get(artistName);
}
tomandrews there you go. google "java code formatter" if you need help cleaning up a post.
It's almost as quick as lol'ing, and about a thousand times more useful.
1 Answer
Mohit Ladia
4,140 PointsThanks Gavin , Can you please help me out with this code ?
tomandrews
13,183 Pointstomandrews
13,183 Pointslol no, who would be able to understand that.