//断言
Predicate<String> p = (s) -> s.startsWith("j");
boolean result = p.test("java");
System.out.println(result);
//消费者
Consumer<String> consumer = System.out::println;
consumer.accept("hello java8");
//函数
Function<String, Integer> function = String::length;
System.out.println(function.apply("lambda"));
//有两个输入参数的函数
BiFunction<String, Integer, Boolean> biFunction = (s, i) -> null != s && i > 0;
System.out.println(biFunction.apply("hello", 19));
//一元函数 (输入输出类型相同)
UnaryOperator<String> unaryOperator = (s) -> s += " lambda";
System.out.println(unaryOperator.apply("hello"));
// 二元函数(输入输出类型相同)
BinaryOperator<String> binaryOperator = (s, f) -> s + f;
System.out.println( binaryOperator.apply("easy ", " java"));
控制台输出
true
hello java8
6
true
hello lambda
easy java
网友评论