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!
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

Nirbhay Agarwal
2,852 PointsCan someone explain what this does is doing exactly here
for (Map.Entry<String, String> option : mMenu.entrySet()) {
System.out.printf("%s - %s %n",
option.getKey(),
option.getValue());
We have a map and its printing getKey() and getValue() of what of this ????????
mMenu is a map here:
mMenu.put("add", "Add a new song to the song book");
mMenu.put("quit", "Give up. Exit the program");
1 Answer

Craig Dennis
Treehouse TeacherHi Nirbhay Agarwal !
So each time you put something into a map, you are adding an entry. An entry consists of a key and a value. So that enhanced for loop is looping through each entry in the map. It can be read as for each entry in the map....
getKey
is getting the key portion so "add"
is a key and "Add a new song to the songbook"
is the value.
Does that make sense?
Nirbhay Agarwal
2,852 PointsNirbhay Agarwal
2,852 PointsYup Craig its grt I completed the KaraokeMachine concept... Thanks