Java Streams and Lambdas
Process collections declaratively with lambdas and the Stream API (Java 8+).
Intermediate
double avg = readings.stream()
.filter(v -> v > 0)
.mapToDouble(Double::doubleValue)
.average()
.orElse(0);
List<String> names = components.stream()
.map(Component::name)
.sorted()
.toList();
Streams describe what to compute; they are lazy and can run in parallel with .parallelStream().
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.