Created
May 16, 2017 07:56
-
-
Save travisdachi/7f93956ac720513561f01639842e185d 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 FilterableArrayList<T> extends ArrayList<T> { | |
public FilterableArrayList(Collection<? extends T> c) { | |
super(c); | |
} | |
public List<T> filter(Predicate<T> predicate) { | |
return filterTo(new ArrayList<T>(), predicate); | |
} | |
public <C extends Collection<? super T>> C filterTo(C destination, Predicate<T> predicate) { | |
for (T element : this) 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