谓词复合
Posted i-hard-working
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了谓词复合相关的知识,希望对你有一定的参考价值。
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())); } }
以上是关于谓词复合的主要内容,如果未能解决你的问题,请参考以下文章