Skip to content
On this page

Streams API:

The Streams API provides a functional-style approach to process collections of data.

java
// Streams API
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);

int sum = numbers.stream()
                 .filter(n -> n % 2 == 0)
                 .mapToInt(n -> n)
                 .sum();

System.out.println("Sum of even numbers: " + sum);