Streams and functional pipelines
Streams express transformations over collections as a readable pipeline.
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.
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
MediumFilter and map lessons
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 inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.