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

Concept

Streams and lambdas

A stream processes a collection as a pipeline of operations, filter, map, sorted, collect, written with lambdas. It replaces many loops with a declarative description of the result.

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. Explain what a stream pipeline is and what a terminal operation does
  2. Rewrite a loop as filter, map and collect
  3. Spot the stream reused after a terminal operation

In practice

A few lines that show Streams and lambdas doing its job.

Java
record Order(String customer, long cents) {}

Map<String, Long> totalByCustomer = orders.stream()
    .filter(o -> o.cents() > 0)
    .collect(Collectors.groupingBy(
        Order::customer,
        Collectors.summingLong(Order::cents)));

List<String> top = totalByCustomer.entrySet().stream()
    .sorted(Map.Entry.<String, Long>comparingByValue().reversed())
    .limit(3)
    .map(Map.Entry::getKey)
    .toList();

The common mistake

Watch for

Reusing a stream after a terminal operation. A stream is consumed once; calling count() and then toList() on the same one throws IllegalStateException.

What to know first

Your roadmap puts these before Streams and lambdas, unless you already know them.

How it stays learned

Once a session shows you understand Streams and lambdas, 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
Previous in the module← Collections and generics