1. Concept library
  2. Java & Spring Boot
  3. Module 1: Modern Java essentials

Concept

Collections and generics

List, Set and Map are the everyday collections, each with several implementations that trade order, lookup speed and memory. Generics give them element types, so the compiler catches a String put into a List<Integer>.

What a session covers

The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.

  1. Choose between ArrayList, HashSet, TreeMap and friends by order, lookup and memory
  2. Write code with typed collections and explain what the compiler catches
  3. Spot the UnsupportedOperationException from List.of

In practice

A few lines that show Collections and generics doing its job.

Java
List<String> names = new ArrayList<>(List.of("ada", "grace"));
names.add("linus");

Map<String, Integer> ages = new HashMap<>();
ages.put("ada", 36);
ages.getOrDefault("bob", 0);

Set<String> unique = new TreeSet<>(names);   // sorted, no duplicates
List<String> fixed = List.of("a", "b");      // immutable: add() throws

The common mistake

Watch for

Calling add or remove on a list from List.of() or Collections.unmodifiableList(). They throw UnsupportedOperationException at runtime; copy into a new ArrayList when you need to change it.

What to know first

Your roadmap puts these before Collections and generics, unless you already know them.

How it stays learned

Once a session shows you understand Collections and generics, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.

  1. Day 3First recall, while it is fresh
  2. Day 7Second, a week on
  3. Day 18Last, when it has settled

Where it leads

Topics that build on Collections and generics.

Previous in the module← Records and var
Next in the moduleStreams and lambdas →