This snippet will sum all digits in an ArrayList using a standard java technique. We will initialize a variable sum and with each iteration of the java 5 for loop add the element to the total which will result to the sum of all numbers in the list.
Java 8
This snippet will sum all values in an ArrayList using java 8 techniques. Java 8 Streams contains reduce operations which provides an internal implementation of sum that enables a cleaner, more maintainable, and eloquent of way of handling summing all elements in an ArrayList. If you are looking to calculate all reduction operations, DoubleSummaryStatistics example is a class which will calculate all statistics such as average, count, min max and sum.
Apache Commons
This snippet will use apache commons to sum all of the values in an ArrayList using StatUtils which provides static methods for computing statistics.