Java MCQ: What is a HashMap in Java?
a) A map that stores key-value pairs with unique keys and allows null values
b) A map that stores keys in a sorted order
c) A map that does not allow null keys or values
d) A list that allows duplicates
Answer:
a) A map that stores key-value pairs with unique keys and allows null values
Explanation:
A HashMap
in Java is a map that stores key-value pairs where each key is unique. It allows one null key and multiple null values. It does not maintain any particular order of its elements.
Understanding HashMap
is crucial for managing collections of key-value pairs where quick lookups and null handling are required.
Reference links:
https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html