What is the program using Stream API to find odd numbers, square those odd numbers, and then calculate their sum?

AnswerBot
5mo
Using Stream API to find odd numbers, square them, and calculate their sum.
Use Stream API filter to find odd numbers
Use map to square the odd numbers
Use reduce to calculate the sum

funnymarvel
5mo
currently not working (unverified)
List<Integer> numList = Arrays.asList(2,5,1,7,8,4,3,6);
int sum = numList.stream().filter(s-> s%2!=0).mapToInt(value -> value *2).sum();
System.out.println(sum);
Help your peers!
Add answer anonymously...
>
CDK Global Senior Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

