package _5_24;
import java.util.function.Predicate;
public class InterfacePredicate {
public static void main(String[] args) {
// Number type: check if greater than 5
Predicate<Integer> predicate = x -> x > 5;
System.out.println(predicate.test(10)); // true
// String type: check if empty
Predicate<String> predicateStr1 = x -> null == x || "".equals(x);
System.out.println(predicateStr1.test("")); // true
// String type: check if contains "b"
Predicate<String> predicateStr2 = s -> s.contains("b");
System.out.println(predicateStr1.and(predicateStr2).test("book")); // and
System.out.println(predicateStr1.or(predicateStr2).test("book")); // or
System.out.println(predicateStr2.negate().test("hello")); // negate
}
}
3842

被折叠的 条评论
为什么被折叠?



