Function<傳入的參數(shù), 返回值>
demo:
Function<String, Integer> func = p -> p.length();
System.out.println(func.apply("dsagrwe")); // 結(jié)果是7
Consumer<傳入的參數(shù)>
demo:
Consumer<String> consumer= str -> System.out.println(str);
consumer.accept("Hello Consumer!"); // 結(jié)果是 Hello Consumer!
Supplier<返回值>
demo:
Supplier<String> supplier= () -> "Hello Supplier!";
System.out.println(supplier.get());
Predicate<傳入的參數(shù)> //這個的返回值是Boolean
demo:
Predicate<String> predicate = str -> str.contains("Hello");
System.out.println(predicate.test("Hello Cool狗"));
個人覺得安岂,如果Predicate懶得記们衙,直接用Function代替:
Function<String, Boolean> func2 = str -> str.contains("Hello");
System.out.println(func2.apply("Hello Cool狗"));
其它: