Skip to content
Veltoryx Technologies
ProLesson 8.4Intermediate2 min readUpdated 30 October 2026

Stream basics: create, filter, map, collect

Process collections declaratively with streams. Create a stream, chain filter and map, finish with a terminal operation, and understand laziness.

A stream is a pipeline for processing data: take a source, transform it step by step, then produce a result. Instead of writing how to loop, you describe what you want.

01Loop vs stream

"Names of paid orders over ₹1,000, in upper case":

LoopVsStream.java
import java.util.ArrayList;
import java.util.List;

record Order(String customer, double amount, boolean paid) { }

public class LoopVsStream {
    public static void main(String[] args) {
        List<Order> orders = List.of(
                new Order("asha", 1500, true),
                new Order("ravi", 800, true),
                new Order("bala", 2500, false),
                new Order("jo", 3000, true));

        // Loop: how to do it
        List<String> loopResult = new ArrayList<>();
        for (Order o : orders) {
            if (o.paid() && o.amount() > 1000) {
                loopResult.add(o.customer().toUpperCase());
            }
        }

        // Stream: what we want
        List<String> streamResult = orders.stream()
                .filter(o -> o.paid() && o.amount() > 1000)
                .map(o -> o.customer().toUpperCase())
                .toList();

        System.out.println(loopResult);
        System.out.println(streamResult);
    }
}
Expected output
[ASHA, JO]
[ASHA, JO]

Loading the rest of the lesson…