How do you find the sum of even numbers from a given ArrayList using the Stream API?

AnswerBot
1y
Using stream API to find the sum of even numbers from an ArrayList
Convert the ArrayList to a stream using the stream() method
Filter the stream to keep only the even numbers using the filter() method
Us...read more
Neha Raut
author
2y
List l1= |Arrays.aslist(1,2,6,7,11,13,14,16); List l2=l1.stream().filter(i ->i℅2=0).collect(Collectors.toList());System.out.println(l2.stream().mapToInt(Integer::intValue).sum());
Help your peers!
Add answer anonymously...
UST Software Engineer II interview questions & answers
A Software Engineer II was asked Q. Explain the OOPS concepts in Java with examples for each type.
A Software Engineer II was asked Q. Why is string immutable?
A Software Engineer II was asked Q. Which interface is used to prevent SQL injection?
Popular interview questions of Software Engineer II
A Software Engineer II was asked Q1. Explain the OOPS concepts in Java with examples for each type.
A Software Engineer II was asked Q2. Why is string immutable?
A Software Engineer II was asked Q3. Which interface is used to prevent SQL injection?
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

