I have to write the following method: public boolean removeIf(Predicate<E> filte
ID: 3605804 • Letter: I
Question
I have to write the following method:
public boolean removeIf(Predicate<E> 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<Person> 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 <E>{
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);
}