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

AnswerBot
13d

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
1d
works at
GA
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
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter