### Question:
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();  }### Answer:
@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); }
@Test public void testFilterOddNumbersOut() { List<Integer> list = Arrays.asList(new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); Collection<Integer> evenNumbers = 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[] {2, 4, 6, 8, 10}); assertEquals(expected, evenNumbers); }