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?
|
map.get(index);
|
|
map.get(key);
|
|
map.get(value);
|
|
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.