Skip to content

Instantly share code, notes, and snippets.

@travisdachi
Created May 16, 2017 07:56
Show Gist options
  • Save travisdachi/7f93956ac720513561f01639842e185d to your computer and use it in GitHub Desktop.
Save travisdachi/7f93956ac720513561f01639842e185d 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 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