TransformUtils { public static <T> Collection<T> filter(Collection<T> items, Predicate<T> predicate) { Collection<T> result = new ArrayList<>(); for (T item : items) { if (predicate.condition(item)) { result.add(item); } } return result; }  static Collection<T> filter(Collection<T> items, Predicate<T> predicate); static Collection<E> map(Collection<T> items, Map<T> mapper);  }
@Test public void testFilter() throws Exception { Collection<Integer> data = Arrays.asList(1, 2, 3, 4, 5); Collection<Integer> evenData = TransformUtils.filter(data, item -> item % 2 == 0); assertEquals(2, evenData.size()); assertTrue(evenData.contains(2)); assertTrue(evenData.contains(4)); }