Java examples for java.util:Collection Element Remove
Copies all elements that match a predicate.
import java.util.Collection; import java.util.function.Predicate; public class Main { /**//from ww w . jav a2s. c om * Copies all elements that match a predicate. * * Every element of the first collection for which the predicate holds (i.e. * returns true) is added to the second collection. */ public static <T> void copySelective(Collection<? extends T> source, Collection<? super T> target, Predicate<T> filter) { for (T t : source) { if (filter.test(t)) { target.add(t); } } } }