Java examples for Lambda Stream:Predicate
filter List with Predicate
//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; } }