See the bellow running code to print the sum of all numbers in a list by using java 8:-
package com.java8.list;
import java.util.Arrays;
import java.util.IntSummaryStatistics;
import java.util.List;
public class SumOfAllNumbersInList {
public static void main(String[] args) {
List<Integer> numbers = Arrays.asList(3, 2, 3, 7, 3, 5);
IntSummaryStatistics intSummaryStatistics = numbers.stream().mapToInt((x) -> x).summaryStatistics();
System.out.println("Sum of numbers : " + intSummaryStatistics.getSum());
}
}
Output:-Sum of numbers : 23