Skip to content
Sharp

Collections · interview question

In an e-commerce catalog system, you want to store categories in a way that offers fast retrieval of a list of subcategories. What would be a suitable collection choice?

Multiple choiceHardchapter-4-curatedpremiumcollectionscollection-performance-basics
Choose one answer
Answer and explanation

Correct answer

D. HashMap<String, List<String>>

Why

A HashMap allows you to associate a category with a list of subcategories, providing O(1) average time complexity for retrieval by key, which is efficient for this use case.

Test yourself on Collections

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

Start free test
All Collections questions →