Skip to content
Sharp

Collections · interview question

How would you explain a key advantage of using a HashMap over a TreeMap in an interview?

Multiple choiceMediumchapter-4-curatedpremiumcollectionschoosing-the-right-collection
Choose one answer
Answer and explanation

Correct answer

C. Faster insertion and lookup

Why

HashMap typically offers faster insertion and lookup operations (O(1) on average) compared to TreeMap, which maintains a sorted order and has O(log n) time complexity for basic operations.

Test yourself on Collections

A free test with instant, explained results. No account needed.

Start free test
All Collections questions →