filter Iterable by Predicate - Android java.util

Android examples for java.util:Iterable

Description

filter Iterable by Predicate

Demo Code


import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

import android.support.annotation.NonNull;

public class Main{
    public static <T> List<T> filter(@NonNull Iterable<T> iterable,
            @NonNull Predicate<T> predicate) {
        List<T> result = new ArrayList<>();

        for (T element : iterable) {
            if (predicate.test(element)) {
                result.add(element);/*from w  w w  .  j  av  a2  s  .com*/
            }
        }

        return result;
    }
}

Related Tutorials