How will you get the sum of all numbers present in a list using Java 8 in Java8?
Following code will print the sum of all numbers present in a list.
List<Integer> numbers = Arrays.asList(3, 2, 2, 3, 7, 3, 5);
IntSummaryStatistics stats = integers.stream().mapToInt((x) -> x).summaryStatistics();
System.out.println("Sum of all numbers : " + stats.getSum());