java8流的filter方法

转载https://blog.csdn.net/qq_20009015/article/details/84891638

List<Integer> evens = new ArrayList<>();
for (final Integer num : nums) {
    if (num % 2 == 0) {
        evens.add(num);
    }
}

List<Integer> evens=num.stream().filter(num->num%2==0).collect(Collectors.toList());

posted @ 2020-05-27 09:35  下饭  阅读(1577)  评论(0编辑  收藏  举报