Java tutorial
//package com.java2s; import java.util.*; import java.util.function.Predicate; public class Main { public static <E> List<E> filter(List<E> elements, Predicate<E> filter) { List<E> result = new ArrayList<>(); for (E element : elements) { if (filter.test(element)) { result.add(element); } } return result; } }