Java Tutorials
Java collections, explained through a Sangli grocery shop
List, Set, Map and Queue stop being abstract the moment you map them onto a shop you have actually walked into. A beginner-friendly guide with real code.
Amit Kulkarni · 24 July 2026 · 2 min read
Most Java tutorials introduce collections as a class hierarchy diagram. That diagram is accurate and completely useless for a beginner. Let's use a shop instead.
The shop
Picture a small grocery shop on Miraj Road. There are four different things going on in it, and each one maps to a collection type.
List — the day's bill register
The register records every sale, in order, and the same item can appear many times.
List<String> billRegister = new ArrayList<>();
billRegister.add("Parle-G");
billRegister.add("Milk");
billRegister.add("Parle-G"); // duplicate is fine and meaningful
System.out.println(billRegister.get(0)); // order matters: Parle-G
Use a List when order matters and duplicates are real data.
Set — the list of items the shop stocks
The shop stocks Parle-G. Saying it twice adds nothing.
Set<String> stocked = new HashSet<>();
stocked.add("Parle-G");
stocked.add("Parle-G");
System.out.println(stocked.size()); // 1
Use a Set when you care about membership, not order or count.
Map — the price board
Every item has exactly one price. You look up by name.
Map<String, Integer> priceBoard = new HashMap<>();
priceBoard.put("Parle-G", 10);
priceBoard.put("Milk", 28);
System.out.println(priceBoard.get("Milk")); // 28
Use a Map when you look things up by a key.
Queue — the customers waiting
First one in is first one served.
Queue<String> counter = new LinkedList<>();
counter.add("Rohit");
counter.add("Sneha");
System.out.println(counter.poll()); // Rohit
Use a Queue when processing order is first-in-first-out.
The one question that picks the right collection
Ask: what am I going to do with this the most?
- Read by position, keep duplicates → List
- Check "is this in here?" → Set
- Look up by a key → Map
- Process in arrival order → Queue
Interviewers ask this constantly, usually as "why did you use an ArrayList here instead of a HashSet?". The shop answer works in an interview too, minus the biscuits.
Next: the performance question
Once the choice is obvious, the follow-up is ArrayList or LinkedList, and HashMap or TreeMap. That is a question about time complexity, and it is the next thing to learn.
- java
- beginners
- collections