filter List with Predicate - Java Lambda Stream

Java examples for Lambda Stream:Predicate

Description

filter List with Predicate

Demo Code


//package com.java2s;
import java.util.ArrayList;
import java.util.List;

import java.util.function.Predicate;

public class Main {
    public static <T> List<T> filter(List<T> list,
            Predicate<? super T> predicate) {
        List<T> filteredList = new ArrayList<>();
        for (T item : list) {
            if (predicate.test(item))
                filteredList.add(item);/*from   w w  w.  j a v  a  2 s  .c o m*/
        }
        return filteredList;
    }
}

Related Tutorials