Java Foundations·Objects that hold up

Streams and functional pipelines

Streams express transformations over collections as a readable pipeline.

Beginner 15 min read Lesson 9 of 300 Challenge included
What you will be able to do
  • Prefer map/filter/collect over manual loops for transformations.
  • Use Collectors.groupingBy for grouped summaries.
  • A stream should not mutate external state.

In plain English

filter, map, sorted and collect compose without mutating the source. A stream is lazy until a terminal operation runs. Keep pipelines short and side-effect free; use method references where they improve clarity.

Lessons.javaJava
import java.util.List;
import java.util.stream.Collectors;

record Lesson(String title, int minutes) {}

List<Lesson> lessons = List.of(
    new Lesson("HTML", 8),
    new Lesson("CSS", 12),
    new Lesson("Grid", 16)
);

List<String> shortTitles = lessons.stream()
    .filter(lesson -> lesson.minutes() < 15)
    .map(Lesson::title)
    .collect(Collectors.toList());
Your turn

Filter and map lessons

Medium

From a list of lessons, keep those under 15 minutes and collect their titles.

JAVA · starter
List<String> titles = lessons.stream()
Check your understanding before moving on.
Knowledge checkQuestion 1

When does a stream process its elements?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: A Spring Boot API
Lesson 9 of 300 · 0% of course