Skip to content
Learn Netverks

Lesson

Step 29/36 81% through track

streams-lambdas

Streams and lambdas

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Streams and lambdas: the syntax, APIs, and habits you need before advancing in Java.

Streams and lambdas are idiomatic in modern Java—teams expect readable collection pipelines in reviews.

You will apply Streams and lambdas in contexts like: Data transforms in services, ETL steps, and readable business logic without boilerplate loops.

Write Java with a public class (lessons use Main), click Run on server—the dev runner runs javac then java; fix compile errors from stderr (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Java 8 added lambda expressions and the Stream API for declarative collection processing—filter, map, reduce without manual index loops.

Lambda syntax

list.forEach(s -> System.out.println(s));
list.sort((a, b) -> a.compareToIgnoreCase(b));

Stream pipeline

long count = names.stream()
    .filter(s -> s.startsWith("A"))
    .map(String::toUpperCase)
    .count();

Streams are lazy until a terminal operation (collect, count, forEach) runs.

Important interview questions and answers

  1. Q: Stream vs parallelStream?
    A: parallelStream uses fork/join—only beneficial on large CPU-bound workloads with thread-safe ops.
  2. Q: Method reference?
    A: Shorthand lambda—String::toUpperCase equivalent to s -> s.toUpperCase().

Self-check

  1. What triggers stream evaluation?
  2. Name two intermediate stream operations.

Pitfall: Streams are single-use—calling a terminal operation twice on the same stream throws IllegalStateException.

Interview prep

When use streams?

Declarative collection transforms—filter/map/reduce—especially when chaining operations; simple loops are fine for trivial cases.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Stream not reusable?
  • map vs flatMap?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump