Java Java Data Structures Efficiency! Implement Chooser UI

Not clear on behavior of method

Can someone explain to me what is the following method doing? Thanks!

public List<Song> getSongsForArtist(String artistName) {

  return byArtist().get(artistName);

2 Answers

Linda de Haan
Linda de Haan
11,221 Points

I still had the entire project on my computer so I could easily take a look for you. But other people that would want to answer your question might not have it. It's best to post your question as complete as possible. Include all relevent code and use markdown, so people can see exactly what your code does and help you answer your question.

Here's what this code does:

getSongsForArtist(String artistName) returns a List of type Song. byArtist returns a map (key-value set) sorted by artistname (key) and all their songs (value) The get() method after byArtist().get() searches for the specific artist in the map. If it finds the artist it puts his songs to a new List of type Song.

One way to easily find out what code does exactly is to either use the debugger of your IDE or write several System.out.println() with relevant text that explains where in the code it is. For example: System.out.println("In the byArtist() method, entering the for loop"). That way you can follow your code using the output to the console.

Thank you, Linda!

You make a good point on adding relevant text to highlight where the code is, therefore identifying what process is actually take place during program execution.

Thank you very much!