Java — Which interface does java.util.Hashtable implement?
Java Programming
Objects and Collections
Difficulty: Easy
Choose an option
-
Ajava.util.Map
-
Bjava.util.List
-
Cjava.util.HashTable
-
Djava.util.Collection
Answer
Correct Answer: java.util.Map
Explanation
Introduction / Context:The java.util.Hashtable class is one of the legacy collection classes in Java. Understanding which interfaces it implements is key to using it correctly in modern Java programming.
Given Data / Assumptions:
- Hashtable is a dictionary-like data structure storing key-value pairs.
- Located in java.util package.
- Modern usage often prefers HashMap, but Hashtable remains important historically.
Concept / Approach:Hashtable implements the Map interface, which defines methods for mapping keys to values without duplicates.
Step-by-Step Reasoning:
Hashtable extends Dictionary (legacy) but implements Map.Map ensures unique keys, allows value lookup, insertion, and removal.List and Collection are not correct because they do not define key-value mapping.Why Other Options Are Wrong:
- List → ordered sequence, not key-value mapping.
- HashTable (spelled incorrectly) is not an interface.
- Collection is more general, but Hashtable implements Map, not Collection directly.
Final Answer:java.util.Map