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 trialIsaias Valdez
1,412 PointsHelp me understand Map<String, List<Song>> byArtist = new HashMap<>();
How does a List of Song objects, with each Song having 3 string values (artist, title, video url) get stored as a single value in a Map? Isn't a Map key only allowed to map to at most one value? Song object has 3 values (mArtist, mTitle, mVideoUrl). How are we able to have a List of Songs as a Map value?
1 Answer
Steven Parker
231,261 PointsA "Song" object may have multiple properties, but it's still one object. And you can put several objects into a list, but the list itself is one thing.
And you're right that a map key can only be associated with one value, but the single value can be a list.