Q1
What is the difference between a HashMap and a TreeMap in Java?
mediumView Answer & ExplanationHide Answer & Explanation
Correct Answer: A HashMap does not guarantee any particular order of keys, while a TreeMap keeps keys sorted
Explanation:
TreeMap implements a sorted structure internally, usually a red-black tree, so iterating over it returns keys in natural or custom sorted order, unlike the unpredictable order of a HashMap.