Performs a reduction on the elements using an associative accumulator.
Syntax
stream.reduce(identity, accumulator)Example
Enter values below to update the example in real time.
List→nums→of→stream→reduce→System→out→println→List<Integer> nums = List.of(1, 2, 3, 4, 5);
int sum = nums.stream()
.reduce(0, Integer::sum);
System.out.println(sum); // 15