MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
How do you get a value from a HashMap?
A
map.get(index);
B
map.get(key);
C
map.get(value);
D
map.valueOf(key);
Explanation: 

Detailed explanation-1: -To retrieve the set of keys from HashMap, use the keyset() method. However, for set of values, use the values() method.

Detailed explanation-2: -Get keys from value in HashMap To find all the keys that map to a certain value, we can loop the entrySet() and Objects. equals to compare the value and get the key. The common mistake is use the entry. getValue().

Detailed explanation-3: -The get() method returns the value corresponding to the specified key in the hashmap.

There is 1 question to complete.