When do you use List, Set, and Map in Java?
PICTURE THIS: ARRAY IN MEMORY
Index starts at 0. Scan once for max — O(n).
Simple meaning
List keeps ordered elements and allows duplicates, like order line items.
WHY — Collections instead of guessing?
Why interviewers care about Collections:
on Collections.
the situation, the default choice, and one exception - that reads as experience.
Name the idea, why it exists, then one short example.
End with when you use it and one common pitfall.
STEPS — What happens step by step?
Before you speak the answer, walk the interviewer through these steps:
- 1List keeps ordered elements
and allows duplicates, like order line items.
- 2Set stores unique elements,
like distinct user ids.
- 3Map stores key-value pairs,
like sku to price.
- 4Pick the interface first,
then ArrayList, HashSet, or HashMap unless you need ordering or concurrency.
- 5Common mistake
What juniors usually get wrong.
- 6Close
When you pick this over the alternative.
EXAMPLE — See it in action
Here's a short line you can speak, broken into clear beats:
Note: Adapt this scaffold to your own project — keep it under 60–90 seconds.
Key takeaway
List keeps ordered elements and allows duplicates, like order line items. Set stores unique elements, like distinct user ids.