@Test public void testFilterEvenNumbersOut() { List<Integer> list = Arrays.asList(new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); Collection<Integer> oddNumbers = filter(list, new Predicate<Integer>() { public boolean apply(Integer i) { if (i % 2 != 0) { return true; } return false; } }); List<Integer> expected = Arrays.asList(new Integer[] {1, 3, 5, 7, 9}); assertEquals(expected, oddNumbers); }
static public <T> Collection<T> filter(Collection<T> target, Predicate<T> predicate) { Collection<T> filteredCollection = new ArrayList<T>(); for (T t : target) { if (predicate.apply(t)) { filteredCollection.add(t); } } return filteredCollection; }
Filter { static public <T> Collection<T> filter(Collection<T> target, Predicate<T> predicate) { Collection<T> filteredCollection = new ArrayList<T>(); for (T t : target) { if (predicate.apply(t)) { filteredCollection.add(t); } } return filteredCollection; } }
Filter { static public <T> Collection<T> filter(Collection<T> target, Predicate<T> predicate) { Collection<T> filteredCollection = new ArrayList<T>(); for (T t : target) { if (predicate.apply(t)) { filteredCollection.add(t); } } return filteredCollection; }  }
Filter { static public <T> Collection<T> filter(Collection<T> target, Predicate<T> predicate) { Collection<T> filteredCollection = new ArrayList<T>(); for (T t : target) { if (predicate.apply(t)) { filteredCollection.add(t); } } return filteredCollection; }  Predicate<Integer> createIntegerBasedPredicate(final int j); Predicate<String> createStringBasedPredicate(final String filterString); static Collection<T> filter(Collection<T> target, Predicate<T> predicate); static void setSearchString(String searchString); static String getSearchString(); }
Filter { static public <T> Collection<T> filter(Collection<T> target, Predicate<T> predicate) { Collection<T> filteredCollection = new ArrayList<T>(); for (T t : target) { if (predicate.apply(t)) { filteredCollection.add(t); } } return filteredCollection; }  Predicate<Integer> createIntegerBasedPredicate(final int j); Predicate<String> createStringBasedPredicate(final String filterString); static Collection<T> filter(Collection<T> target, Predicate<T> predicate); static void setSearchString(String searchString); static String getSearchString();  }