Last active
May 16, 2017 07:58
-
-
Save travisdachi/15d951b6598eed23629abd449f29be76 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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