COMPUTER SCIENCE AND ENGINEERING
DATA STRUCTURES
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
How do you add an element to a HashMap with String keys and Integer values?
|
map.put(Stuff, 123);
|
|
map.add("Stuff", 123);
|
|
map.put("Stuff", 123);
|
|
map.add(Stuff, 123);
|
Explanation:
Detailed explanation-1: -To add elements to HashMap, use the put() method.
Detailed explanation-2: -Java HashMap put() is a method that is used to add key/value pairs inside a hashmap.
Detailed explanation-3: -Inserting Elements Into a Java Map To add elements to a Map you call its put() method. Here are a few examples: Map<String, String> map = new HashMap<>(); map. put("key1", “element 1"); map.
There is 1 question to complete.