Java MCQ: What is a TreeMap in Java?
a) A map that stores keys in a sorted order
b) A map that allows null keys
c) A map that does not allow duplicate keys
d) A map that uses a linked list internally
Answer:
a) A map that stores keys in a sorted order
Explanation:
A TreeMap
in Java is a map that stores its keys in a sorted order, either based on their natural ordering or a specified comparator. It does not allow null keys but allows multiple null values.
Understanding TreeMap
is essential for managing key-value pairs where sorted order is required in addition to uniqueness.
Reference links:
https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html