Java8函数式接口之Predicate<T>

作用:

这是一个功能接口,因此可以作为lambda表达式或方法引用的赋值目标。

实例:

/**
 * Created by luo on 2017/5/3.
 */
public class PredicateTest {
    public static List<Integer> integerList = Arrays.asList(1,2,3);
    public static void main(String[] args) {
        List<Integer> list = filte(i->i>1);
        list.forEach(System.out::println);
    }

    public static List<Integer> filte(Predicate<Integer> predicate){
        List<Integer> list = new ArrayList();
        integerList.forEach(i -> {if (predicate.test(i)){
            list.add(i);
        }});
        return list;
    }
}

 

posted on 2017-05-03 21:54  Simle  阅读(456)  评论(0编辑  收藏  举报