Sum of numbers

Report a typo

Given a list of integer numbers:

List<Integer> numbers = Arrays.asList(0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55);

Here is a piece of code with streams:

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

The result is ...

Enter a number
___

Create a free account to access the full topic