COMPUTER SCIENCE AND ENGINEERING
DATA STRUCTURES
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
with Strings as
|
HashMap<String, Integer> map = new HashMap<String, Integer>();
|
|
HashMap<String> map = new HashMap<Integer>();
|
|
HashMap<Integer, String> map = new HashMap<Integer, String>();
|
|
HashMap map = new HashMap(String, Integer);
|
Explanation:
Detailed explanation-1: -Here, K represents the key type and V represents the type of values. For example, HashMap<String, Integer> numbers = new HashMap<>(); Here, the type of keys is String and the type of values is Integer .
Detailed explanation-2: -String is as a key of the HashMap When you create a HashMap object and try to store a key-value pair in it, while storing, a hash code of the given key is calculated and its value is placed at the position represented by the resultant hash code of the key.
There is 1 question to complete.