J
JavaCraft
← Back to all posts

Core Java · Collections

Java Collections – List, Set, Map Explained

Published: Nov 17, 2025 8 min read By Sanjay
Collections List Set Map

Java Collections Framework is one of the most important foundations of backend development. Every Spring Boot project heavily uses Lists, Sets, and Maps for storing and transferring data.

1. List – Ordered & Allow Duplicates

A List maintains insertion order and allows duplicate values.


List<String> names = new ArrayList<>();
names.add("Sanjay");
names.add("Sanjay"); // duplicate
System.out.println(names);

Use List when ordering matters.

2. Set – Unique Elements Only

A Set removes duplicates automatically.


Set<String> items = new HashSet<>();
items.add("Java");
items.add("Java"); // ignored
System.out.println(items);

Use Set when uniqueness matters.

3. Map – Key/Value Pairs


Map<String, Integer> scores = new HashMap<>();
scores.put("Math", 95);
scores.put("Java", 90);
System.out.println(scores.get("Java"));

Use Map when storing objects by key.

Final thoughts

If you're building Spring Boot APIs, you’ll use Lists for responses, Maps for JSON-like structures, and Sets for uniqueness. Understanding these three deeply will improve your backend skills.