Lesson 19: Streams API & Lambda Expressions

20 Jul 2026 1 min Swarnil Singhai

Streams let you express data transformations declaratively — filter, map, reduce — instead of manual loops with mutable state.

Real-time example

An analytics dashboard computes total revenue from orders over Rs 500 in one readable pipeline instead of a manual for-loop with an accumulator.

List<Order> orders = List.of(
    new Order("A", 600), new Order("B", 300), new Order("C", 900));

double total = orders.stream()
    .filter(o -> o.amount > 500)
    .mapToDouble(o -> o.amount)
    .sum();
System.out.println(total); // 1500.0

What's happening

filter and mapToDouble are lazy — nothing runs until sum() (a terminal operation) triggers the pipeline.

Streams shine for read/transform pipelines; plain loops are still clearer for side-effect-heavy logic.

Advertisement