In java-8 you can use streams:
int[] a = {10,20,30,40,50};
int sum = IntStream.of(a).sum();
System.out.println("The sum is " + sum);
Output:
The sum is 150.
It's in the package java.util.stream
import java.util.stream.*;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…