The Java Collections Framework: List, Set and Map Overview
A beginner map of the Java Collections Framework — why collections beat arrays, and the three core types List, Set and Map, with a first taste of ArrayList.
Back in Lesson 10 you learned arrays — but arrays have a big limitation: their size is fixed forever the moment you create them. Real programs need collections that can grow and shrink, that can look things up instantly, or that automatically reject duplicates. That's what the Java Collections Framework gives you: a ready-made toolbox of flexible data structures. This lesson is your map to it; the next few lessons dive into the details.
Why collections beat plain arrays
| Array | Collection (e.g. ArrayList) |
|---|---|
| Fixed size — set once | Grows and shrinks automatically |
| Few built-in operations | Rich methods: add, remove, search, sort… |
| One structure only | Many types for different jobs |
The big picture: three families
The Collections Framework is organised around a few core interfaces (remember interfaces from Lesson 17?). The three you'll use most are List, Set, and Map. Here's the mental model — learn this and the rest falls into place:
- List — an ordered collection that allows duplicates, accessed by index. Like a to-do list. (Lesson 22)
- Set — a collection of unique items, no duplicates allowed. Like a set of tags. (Lesson 22)
- Map — stores key → value pairs for fast lookup by key. Like a dictionary. (Lesson 22)
A first taste: ArrayList
The single most-used collection is ArrayList — think of it as a resizable array. Here it is in action:
import java.util.ArrayList; ArrayList<String> fruits = new ArrayList<>(); fruits.add("Apple"); // grows automatically fruits.add("Banana"); System.out.println(fruits.get(0)); // Apple System.out.println(fruits.size()); // 2 fruits.remove("Apple"); // shrinks automatically
No fixed size, and handy methods (add, get, size, remove) right out of the box. That's the whole appeal.
That <String> — generics
Notice ArrayList<String> — the <String> part says "this list holds Strings." It's called generics, and it keeps your collections type-safe (you can't accidentally put a number in a list of Strings). We'll cover generics properly in Lesson 23 — for now, just read it as "a list of Strings."
Iterating a collection
The for-each loop you already know works beautifully here:
for (String fruit : fruits) {
System.out.println(fruit);
}
The Collections Framework is one of the most valuable parts of Java to know well — you'll reach for it in almost every real program. This website uses lists and maps constantly: a list of blog posts to display, a map of settings looked up by key, sets of unique tags. Getting comfortable choosing the right collection for the job (which we'll build up over the next lessons) is a skill that immediately makes your code cleaner and faster.
Key takeaways
- The Collections Framework gives you flexible, resizable data structures beyond fixed arrays.
- The three main types: List (ordered, duplicates), Set (unique), Map (key→value).
ArrayListis the everyday resizable list —add,get,size,remove.<String>is generics — it makes a collection type-safe.
← Previous: Lesson 20 — Exception Handling
Next: Lesson 22 — List, Set & Map in Detail →