0
How will you get the sum of all numbers present in a list using Java 8 in Java8?

Open 1 Answers 60 Views Education

How will you get the sum of all numbers present in a list using Java 8 in Java8?

1 Answer

0

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());
by (53.7k points)
...