QCan the Java for-each loop be used to iterate over a Map collection?
Question Info
Choose the Best Option
Click any option to instantly check if you're correct.
Explanation
In Java, the for-each loop can indeed be used to iterate over a Map collection, but this must be done by utilizing methods such as keySet(), values(), or entrySet(). When using keySet(), the loop iterates over the keys of the map, allowing you to access the corresponding values through each key. The syntax would look like this: for (String key : map.keySet()) {}, where map is the instance of the Map. Alternatively, you can use for (Map.Entry
Share This Question
Challenge a friend or share with your study group.