Question: I have to write the following method: public boolean removeIf(Predicate filter) - Removes all of the elements of this collection that satisfy the given predicate.

I have to write the following method:

public boolean removeIf(Predicate filter) - Removes all of the elements of this collection that satisfy the given predicate. Returns true if at least one element is removed from the list. Otherwise, the method returns false.

* Use the removeIf method and a lambda expression to remove Person

* objects whos age is less than 30

*/

System.out.println(" Display Person list after remove age < 30: ");

for (Person p : arrP) {

System.out.println(p);

}

MyCollection tmpP = new MyArrayList<>();

tmpP.add(new Person("Pilar", "Ess", 34));

tmpP.add(new Person("Jill", "Z", 30));

arrP.retainAll(tmpP);

System.out.println(" Display Person list after retainAll: ");

for (Person p : arrP) {

System.out.println(p);

I need this method to be added to following MyCollection interface:

public interface MyCollection { public boolean add(E item); public void add(int index,E item); public E get(int index); public E remove(int index); public boolean remove(Object o); public void clear(); public E set(int index, E item); public int size(); public boolean contains(Object o); public boolean isEmpty(); public int indexOf(Object o); }

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!