Remove objects from an ArrayList based on a given criteria

You can use Collection::removeIf(Predicate filter) (available from Java8 onwards), here is a simple example:

final Collection<Integer> list = new ArrayList<>(Arrays.asList(1, 2));
list.removeIf(value -> value < 2);
System.out.println(list); // outputs "[2]"

Leave a Comment