java 流常用接口_java8 流 中的常用函数式接口

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 章

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值