Lesson content
Read, practise, then check your understanding
A Stream is a single-use lazy pipeline, not a collection. Intermediate operations build the pipeline; a terminal operation consumes it.
Declarative transformation
List<String> result = names.stream()
.filter(name -> !name.isBlank())
.map(String::trim)
.distinct()
.sorted()
.toList();
Use map for one-to-one transformation, flatMap for nested sources, and reduce/collectors for aggregation. Avoid stateful side effects and modifying the source. Parallel streams require associative operations, splittable data, sufficient work, and careful common-pool impact; measure before enabling. Streams holding I/O resources require try-with-resources.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.