Is there possibility of sum of ArrayList without looping?
ArrayList
PHP provides sum(array) which will give the sum of array.
sum(array)
The PHP code is
This can be done with reduce using method references reduce(Integer::sum):
reduce(Integer::sum)
Integer reduceSum = Arrays.asList(1, 3, 4, 6, 4) .stream() .reduce(Integer::sum) .get();
Or without Optional:
Optional
Integer reduceSum = Arrays.asList(1, 3, 4, 6, 4) .stream() .reduce(0, Integer::sum);