Skip to content

Instantly share code, notes, and snippets.

@travisdachi
Last active May 16, 2017 07:58
Show Gist options
  • Save travisdachi/15d951b6598eed23629abd449f29be76 to your computer and use it in GitHub Desktop.
Save travisdachi/15d951b6598eed23629abd449f29be76 to your computer and use it in GitHub Desktop.
package com.blacklenspub.android.playground;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class ListUtil {
public static <T> List<T> filter(Iterable<T> source, Predicate<T> predicate) {
return filterTo(source, new ArrayList<T>(), predicate);
}
public static <T, C extends Collection<? super T>> C filterTo(Iterable<T> source, C destination, Predicate<T> predicate) {
for (T element : source) if (predicate.check(element)) destination.add(element);
return destination;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment