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

Java

ByArtist method - I don't get it!

First of all, as always, thank you in advance!

So, the thing is: this method is suppose to return a Map<String, List<Song>> with Artist (String) and Song(s) (List of Song>.

here is the code (can somebody please fix it? somehow it doesn't show correctly!):

  private Map<String, List<Song>> byArtist() {
    Map<String, List<Song>> byArtist = new HashMap<String, List<Song>>;

    for (Song song : Songs) {
      List<Song> artistSongs = byArtist.get(song.getArtist());
      if ( artistSongs = null ) {
        artistSongs = new ArrayList<>();
        byArtist.put(song.getArtist(), artistSongs); //PERO SI ESTÁ PONIENDO UN ARRAY VACÍO...
      }
      artistSongs.add(song);
    }
    return byArtist;

  }

The thing is, I DON'T SE WHEN IT SAVES THE SONGS OF THE ARTIST!

I mean, it does artistSong.add(song), but it doesn't assign that new "uploaded" list to the byArtist map!

It works, but I can't see why!

Can some moderator please comment the code so we can understand it step by step?

Thank you!

YOU ROCK!

[MOD: edited code block - srh]