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

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
Here is the code for both tasks Write a foreach using a lambda expression to print all the el... View full answer
Get step-by-step solutions from verified subject matter experts
