首页 > 其他 > 详细

谓词复合

时间:2018-09-03 01:29:58      阅读:190      评论:0      收藏:0      [点我收藏+]
package com.ant.jdk8.chap03;

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

public class PredicateCompositeDemo {
    public static void main(String[] args) {
        List<Apple> apples = Arrays.asList(
                new Apple("green",200,"China"),
                new Apple("green",130,"Japan"),
                new Apple("red",150,"America"),
                new Apple("brown",170,"Thailand"));
        Predicate<Apple> redPredicate = apple->"red".equals(apple.getColor());
        Predicate<Apple> notRedAndHeavyPredicate = redPredicate.negate().and(a->a.getWeight()>150);
        apples.stream().filter(notRedAndHeavyPredicate).
                forEach(a-> System.out.println(a.getColor()+"->"+a.getCountry()+"->"+a.getWeight()));
    }
}

技术分享图片

谓词复合

原文:https://www.cnblogs.com/i-hard-working/p/9575862.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!