COMPUTER SCIENCE AND ENGINEERING
DATA STRUCTURES
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
How do you iterate through a HashMap using a for each loop?
|
for each (String key:map.keySet()) {}
|
|
for each (String key:map) {}
|
|
for (String key:map) {}
|
|
for (String key:map.keySet()) {}
|
Explanation:
Detailed explanation-1: -Using keyset() and value() method keyset(): A keySet() method of HashMap class is used for iteration over the keys contained in the map. It returns the Set view of the keys. values(): A values() method of HashMap class is used for iteration over the values contained in the map.
There is 1 question to complete.