MCQ IN COMPUTER SCIENCE & ENGINEERING

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?
A
for each (String key:map.keySet()) {}
B
for each (String key:map) {}
C
for (String key:map) {}
D
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.