Multi-stream: one summary card from three unrelated feeds

A dashboard tile is usually three small pipelines, not one clever one. Each feed answers its own question - count, filtered count, distinct count - and they only meet in the output.

Code
record Order(String ref, double amount) {}
record Ticket(String id, String state) {}
record Signup(String email) {}

var orders = List.of(new Order("A-1", 120.0), new Order("A-2", 80.0));
var tickets = List.of(new Ticket("T1", "open"), new Ticket("T2", "closed"), new Ticket("T3", "open"));
var signups = List.of(new Signup("a@x.io"), new Signup("b@x.io"), new Signup("a@x.io"));

System.out.println("orders  : " + orders.size()
        + " worth " + orders.stream().mapToDouble(Order::amount).sum());
System.out.println("tickets : " + tickets.stream().filter(t -> t.state().equals("open")).count()
        + " open of " + tickets.size());
System.out.println("signups : " + signups.stream().map(Signup::email).distinct().count() + " unique");
Output
orders  : 2 worth 200.0
tickets : 2 open of 3
signups : 2 unique
Advertisement
More in JAVA

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-09-20

© Java Coding Hub · About · Contact · Privacy · Terms