How do you choose between List, Set and Map for a new feature?
Reviewed by Gurusankar M.
Short Answer
List = ordered, allows duplicates, index access. Set = unique elements, membership tests. Map = key→value lookups. Pick by the question you ask most: 'what's at position i?' (List), 'have I seen this?' (Set), 'what's the value for this key?' (Map).
On this page
Concept Made Simple
Coffee Chat Question
“How do you choose between List, Set and Map for a new feature?”
Remember It Faster
Mind Map Answer
- List (ArrayList)
- ordered, duplicates, O(1) index
- Set (HashSet)
- unique, O(1) contains
- Map (HashMap)
- key→value, O(1) get
- Need order?
- LinkedHashSet/Map or TreeSet/Map
Think Beyond the Expected
What If?
You need uniqueness AND insertion order — which collection?
LinkedHashSet: it rejects duplicates like HashSet but preserves insertion order via a linked list, so iteration is predictable — ideal for de-duplicating a stream while keeping first-seen order.
Real World
Deduplicating user roles → Set; an ordered cart of line items → List; looking up a product by SKU → Map. Picking wrong (e.g. List.contains in a hot path) is a top cause of O(n²) slowness.
Interviewer's Expectation
Keywords they're listening for:
- duplicates vs uniqueness
- index vs key vs membership
- ordering variants
- Big-O of contains/get
Common Mistakes
- Using List.contains() for membership in a loop (O(n²))
- Using a Map when a Set (keys only) suffices
- Assuming HashMap/HashSet preserve order
Best Practices
- Match the structure to your dominant access pattern
- Use a Set for membership, not List.contains
- Reach for Linked*/Tree* variants only when you need ordering
Follow-up Questions
- When does List.contains() become a performance problem?
- How do you keep insertion order in a Set or Map?
- When would you use a sorted structure (TreeMap/TreeSet)?
Continue Learning with AI
Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly — AI is your learning companion, not a shortcut.
Plain-language foundations
I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner. Topic: List vs Set vs Map (Java Collections) Interview question: "How do you choose between List, Set and Map for a new feature?" Please: 1. Explain the core idea in simple, plain language, using an everyday analogy. 2. Define any technical terms you use. 3. Walk through one small, concrete example. 4. Finish with a single sentence I can easily remember. Keep the tone friendly and assume I'm new to this topic.
Was this answer helpful?
Affiliate links
Tools for Your Developer Workspace
Equipment for a comfortable, productive setup.
As an Amazon Associate I earn from qualifying purchases.
- MonitorView on Amazon : BenQ EW2790U 27-inch Monitor (opens in a new tab)
BenQ EW2790U 27-inch Monitor
- LaptopView on Amazon : Acer Aspire One Laptop (opens in a new tab)
Acer Aspire One Laptop
- Office ChairView on Amazon : Wakefit Gravita Ergonomic Office Chair (opens in a new tab)
Wakefit Gravita Ergonomic Office Chair