sum of list java

Solutions on MaxInterview for sum of list java by the best coders in the world

showing results for - "sum of list java"
Juliana
27 Oct 2018
1doubleList.stream().reduce((a,b)->a+b).get();
2
Serena
12 Nov 2018
1int sum = (list.stream().
2        mapToInt(i -> i.intValue()).sum()
Emilie
26 Jun 2020
1double sum = 0;
2for(int i = 0; i < m.size(); i++)
3    sum += m.get(i);
4return sum;
5
Lena
12 Feb 2018
1//If you have a List<Integer>
2int sum = list.stream().mapToInt(Integer::intValue).sum();
3
4//If it's an int[]
5int sum = IntStream.of(a).sum();
similar questions
queries leading to this page
sum of list java