Difficulty: Medium
Correct Answer: LinkedHashMap
Explanation:
Introduction / Context:This question tests knowledge of different Map implementations in Java and their ordering characteristics.
Concept / Approach:
Step-by-Step Reasoning:
If you want the iteration order of an existing Map to be preserved, use LinkedHashMap and construct it with the existing Map.Why Other Options Are Wrong:TreeMap re-sorts keys, HashMap randomizes order, and "depends on implementation" is too vague.
Final Answer:LinkedHashMap
Discussion & Comments