# Java Level 4: Collections & Generics

> Level 4: Collections & Generics of the LoWisa Java course: Lists, Sets and Maps, Generic Types, Choosing Appropriate Collections. 3 lessons and 9 ideas, each explained in one line.

Collections & Generics is level 4 of 16 of the [LoWisa Java course](/courses/java/). It has 3 lessons and 9 ideas. Below is every lesson and what it teaches, in one line each.

## Lists, Sets and Maps

- **List.** A **List** is an ordered collection: ArrayList backs it with a growable array, the everyday default.
- **Set.** A **Set** holds each element once: HashSet answers contains in constant time via hashing.
- **Map.** A **Map** pairs keys with values: HashMap is the lookup table most Java programs are built around.

## Generic Types

- **Generics.** **Generics** parameterise types: List<Order> can only hold orders, checked at compile time, no casts.
- **Type erasure.** Generics are **erased** at runtime: the JVM sees plain List, which is why new T() cannot compile.
- **Bounded types.** A **bound** like <T extends Comparable<T>> demands capability: sort only what can compare itself.

## Choosing Appropriate Collections

- **Choosing by operation.** Choose by the hot **operation**: random access wants ArrayList, membership wants HashSet, ordering wants TreeMap.
- **equals and hashCode.** Hash collections trust **equals** and hashCode together: override one without the other and elements vanish.
- **Immutable collections.** List.of and Map.of build **immutable** collections: safe to share, impossible to corrupt.

## Before and after this level

- **Before:** [Level 3: Interfaces & Polymorphism](/courses/java/level-3-interfaces-and-polymorphism/): Interfaces and Abstract Classes, Dynamic Dispatch, Designing Flexible Object Models.
- **Next:** [Level 5: Exceptions](/courses/java/level-5-exceptions/): Checked and Unchecked Exceptions, Error Propagation, Reliable Exception Design.

In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See [Checkpoints and flashcards](/help/checkpoints-and-flashcards/).

## Frequently asked questions

### What does Java Level 4: Collections & Generics cover?

Lists, Sets and Maps, Generic Types, Choosing Appropriate Collections: 3 lessons and 9 ideas.

### What should I know before this level?

The level before it, Level 3: Interfaces & Polymorphism, which covers Interfaces and Abstract Classes, Dynamic Dispatch, Designing Flexible Object Models.

## Learn Java on your phone

The first level is free. LoWisa is on Google Play and the App Store.

---

Source: https://lowisa.dev/courses/java/level-4-collections-and-generics/ · Updated 2026-11-16
