Question: Given the following code: 1. Write a foreach using lambda expression to print all the elements of the ArrayList. (2 pts) 2. Write a

image

Given the following code: 1. Write a foreach using lambda expression to print all the elements of the ArrayList. (2 pts) 2. Write a lambda expression that returns the average of all the elements' lengths in the ArrayList. If you have this functional interface: interface Calc{ double calculate (ArrayList items); } Sample input and output: Input: ArrayList items = new ArrayList (); items.add("Bob"); items.add("Samantha"); items.add("Emily"); items.add("Jack"); items.add("Lina"); ArrayList items = new ArrayList (); Output: 4.8

Step by Step Solution

3.36 Rating (149 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Here is the code for both tasks Write a foreach using a lambda expression to print all the el... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!