How do you find the sum of all the numbers in an array in Java?

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.*;

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)