List lowCaloricDishesName =
menu.parallelStream()
.filter(d -> d.getCalories() < 400)
.sorted(comparing(Dishes::getCalories))
.map(Dish::getName)
.collect(toList());
Map> dishesByType =
menu.stream().collect(groupingBy(Dish::getType));
BiFunction biFunction = (x, y) -> {
return x+"==="+y;
};
Function fun = x ->x + " after8";
System.out.println(biFunction.andThen(fun).apply("tpyyes.com ", " java8"));
函数式接口 函数描述符 原始类型特化
Predicate T->boolean IntPredicate,LongPredicate, DoublePredicate
Consumer T->void IntConsumer,LongConsumer, DoubleConsumer
Function T->R IntFunction,
IntToDoubleFunction,
IntToLongFunction,
LongFunction,
LongToDoubleFunction,
LongToIntFunction,
DoubleFunction,
ToIntFunction,
ToDoubleFunction,
ToLongFunction
Supplier ()->T BooleanSupplier,IntSupplier, LongSupplier,
DoubleSupplier
UnaryOperator T->T IntUnaryOperator,
LongUnaryOperator,
DoubleUnaryOperator
BinaryOperator (T,T)->T IntBinaryOperator,
LongBinaryOperator,
DoubleBinaryOperator
BiPredicate (L,R)->boolean
BiConsumer (T,U)->void ObjIntConsumer,
ObjLongConsumer,
ObjDoubleConsumer
BiFunction (T,U)->R ToIntBiFunction,
ToLongBiFunction,
ToDoubleBiFunction
表4-1 中间操作
操 作 类 型 返回类型 操作参数 函数描述符
filter 中间 Stream Predicate T -> boolean
map 中间 Stream Function T -> R
limit 中间 Stream
sorted 中间 Stream Comparator (T, T) -> int
distinct 中间 Stream
表4-2 终端操作
操 作 类 型 目 的
forEach 终端 消费流中的每个元素并对其应用Lambda。这一操作返回void
count 终端 返回流中元素的个数。这一操作返回long
collect 终端 把流归约成一个集合,比如List、Map 甚至是Integer。详见第6 章