in Education by

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

1 Answer

0 votes
by

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

Related questions

0 votes
    How will you get the highest number present in a list using Java 8...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    How will you print 10 random numbers using forEach of java 8 ?...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    How will you sort a list of string using Java 8 lambda expression?...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    How will you get the instant of zoned date time using time in of milliseconds using java8 in Java8?...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    How will you get the instant of local date time using time in of milliseconds using java8 in Java8?...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    How will you get the instant of current date in terms of milliseconds using java8 in Java8?...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    How will you get second saturday of next month using java8 in Java8?...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    How will you get next tuesday using java8 in Java8?...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    How will you get the current date using local datetime api of java8 in Java8?...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    How will you print 10 random numbers in a sorted order in Java 8?...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    How will you print 10 random numbers in Java 8?...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    How will you print unique squares of numbers in Java 8?...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    Can you execute javascript code from java 8 code base in Java8?...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
0 votes
    A die is thrown twice and the sum of the numbers appearing is observed to be 8. What is the conditional ... appeared at least once? Select the correct answer from above options...
asked Nov 21, 2021 in Education by JackTerrance
...