Question: I need help with this Java question. Please provide the final code and output if possible. Part 2: Methods with Predicate parameters Write the following

I need help with this Java question. Please provide the final code and output if possible.

Part 2: Methods with Predicate parameters

Write the following methods:

1.) public static List collect(List originalList, Predicate predicate): collects all the elements of originalList that satisfy the given predicate into a new list, which it returns. For example, if we have

List integers = List.of(5, -8, 0, 7, 3, -2);

Predicate isPositive = x -> x.doubleValue() > 0;

then collect(integers, isPositive) should return a List representing [5, 7, 3].

2.) public static int find(List list, Predicate predicate): Returns the index of the first element of the list that satisfies the given predicate. If none of the elements satisfy the predicate, returns -1.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!