Java — Which interface provides capability to store objects using key-value pairs?
Java Programming
Objects and Collections
Difficulty: Easy
Choose an option
-
Ajava.util.Map
-
Bjava.util.Set
-
Cjava.util.List
-
Djava.util.Collection
Answer
Correct Answer: java.util.Map
Explanation
Introduction / Context:This tests knowledge of the Map interface in the Java Collections Framework.
Concept / Approach:Map defines methods to store key-value pairs, where keys are unique and values can be retrieved by keys.
Why Other Options Are Wrong:
- Set → stores unique elements only, no key-value.
- List → ordered collection of elements, allows duplicates.
- Collection → root interface, but no key-value mapping.
Final Answer:java.util.Map