GCGrowCarrer

Streams

Locked

Lesson 21 of 60 · DataStructures · Challenging

Finish these first:Lists and Sets →Lambdas and Functional Interfaces →Or pass the tests below to unlock it now.

1

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.
Key words (tap to learn):
2

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.

3

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?

4

Your challenge

2 sample tests, 1 hidden

Write static List<Integer> evenSquares(List<Integer> xs) using a stream.

Stuck? Get a hint (free)
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.

Mastery0%

Opens up next

This is the last lesson in this branch.