Which of the follwoing is not true about hashmap?a)It may have a single null key and multiple null values.b)It does not contain unique elements.c)HashMap contains value based on the key.d)It works on the principle of hashing.e)HashMap does not maintain order while iterating.
Question
Which of the follwoing is not true about hashmap?a)It may have a single null key and multiple null values.b)It does not contain unique elements.c)HashMap contains value based on the key.d)It works on the principle of hashing.e)HashMap does not maintain order while iterating.
Solution
The statement that is not true about HashMap is:
b) It does not contain unique elements.
Explanation: This statement is incorrect because HashMap does contain unique elements. In a HashMap, the keys are unique. You cannot have duplicate keys in a HashMap. Each key maps to a single value, and this pairing of a key and a value is considered as one unique element in the HashMap. So, while you can have duplicate values, the keys must be unique.
Similar Questions
Is the implementation of Map, which doesn't maintain any order.a)linkedhash mapb)hashmapc)treemapd)liste)map
What is true about HashMap as a collection type?This collection type can contain duplicate values.If a value is added to this collection type that exists, it will not be checked first.This collection type uses index values to track data.This collection type uses key-value pairs to track data.
What differences exist between HashMap and Hashtable?
What happens when you put a key-value pair in a HashMap where the key already exists?
What is the output of the following code?import java.util.*;public class Main { public static void main(String[] args) { Map map = new HashMap<>(); map.put("A", 1); map.put("B", 2); map.put("C", 3); for (Map.Entry entry : map.entrySet()) { if (entry.getValue() == 2) { map.remove(entry.getKey()); } } System.out.println(map); }}a){A=1, C=3}b)IllegalArgumentExceptionc){A=1, B=2, C=3}d){B=2, A=1, C=3}e)ConcurrentModificationException
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.