Java — Which collection class allows key-value associations and provides synchronization?
Java Programming
Objects and Collections
Difficulty: Easy
Choose an option
-
Ajava.util.SortedMap
-
Bjava.util.TreeMap
-
Cjava.util.TreeSet
-
Djava.util.Hashtable
Answer
Correct Answer: java.util.Hashtable
Explanation
Introduction / Context:This checks knowledge of synchronized collections and legacy classes.
Concept / Approach:
- Hashtable is synchronized, meaning its methods are thread-safe.
- It stores key-value pairs like HashMap but synchronizes all methods.
- TreeMap → ordered keys, but not synchronized.
- SortedMap → interface, not a class.
- TreeSet → stores unique values, not key-value pairs.
Final Answer:java.util.Hashtable