Streams
LockedLesson 21 of 60 · DataStructures · Challenging
Finish these first:Lists and Sets →Lambdas and Functional Interfaces →Or pass the tests below to unlock it now.
The big idea
Streams express pipelines: source → intermediate ops (filter, map, sorted) → terminal op (collect, sum, reduce). Streams are lazy and single-use.
Think of it like this: Think of data structures as specialized toolboxes: a List keeps items in numbered slots (`0, 1, 2...`), a Set keeps only unique badges, and a Dictionary/Map labels each compartment with a custom name key.
Read the lesson
Streams express pipelines: source → intermediate ops (filter, map, sorted) → terminal op (collect, sum, reduce).
List<Integer> sq = xs.stream()
.filter(x -> x % 2 == 0)
.map(x -> x * x)
.toList();
Streams are lazy and single-use.
Quick check
Before writing code: What should `Solution.evenSquares(java.util.List.of(1,2,3,4))` return when your implementation of Streams is working?
Your challenge
Write static List<Integer> evenSquares(List<Integer> xs) using a stream.
More learning tools(compare languages, visual guide, related lessons)
Compare with another language
Similar to python.list-comprehensions (60% overlap). Comprehensions ~ stream `filter`/`map`/`toList`.
Visual walkthrough
A diagram, a step-by-step animation, and short captions for Streams.
Learn this first
- Lists and SetsNot yet
- Lambdas and Functional InterfacesNot yet
Opens up next
This is the last lesson in this branch.