1.

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

Answer»

Following CODE will PRINT the average 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("Average of all numbers : " + stats.getAverage());

Following code will print the average 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("Average of all numbers : " + stats.getAverage());



Discussion

No Comment Found