filter Collection by android Predicate - Android java.util

Android examples for java.util:Collection Filter

Description

filter Collection by android Predicate

Demo Code


import com.android.internal.util.Predicate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class Main{
    public static <E> List<E> filter(Collection<E> src, Predicate<E> p) {
        final ArrayList<E> res = new ArrayList<>();
        for (E elem : src) {
            if (p.apply(elem)) {
                res.add(elem);/* w  w w .  j  a v  a  2s  .  c o  m*/
            }
        }
        return res;
    }
}

Related Tutorials