1.

How Will You Get The Sum Of All Numbers Present In A List Using Java 8?

Answer»

Following CODE will print the SUM of all numbers present in a list.

List 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());

Following code will print the sum of all numbers present in a list.

List 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());



Discussion

No Comment Found