Java函数式编程&Stream流

13.1常用的函数式接口总结

接口名称 方法名称 抽象/默认
 延迟/终结
方法描述
Supplier get 抽象 终结 供给型接口,无参有返回值,主要用于
Consumer accept 抽象 终结 消费型接口,有参数无返回值

andThen 默认 延迟
Function apply 抽象 终结 函数型接口,有参数有返回值

andThen 默认 延迟

compose 默认 延迟
Predicate test 抽象 终结 断言型接口,元芳你怎么看

and 默认 延迟

or 默认 延迟

negate 默认 延迟
notes:
        - 延迟方法:只是在拼接Lambda函数模型的方法,并不立即执行得到结果。
        - 终结方法:根据拼好的Lambda函数模型,立即执行得到结果值的方法。

13.2 Stream流
        13.2.1 获取流的三种方式
                
   public static void main(String[] args) {

       // Collection 集合
       Collection c = new ArrayList();
       Stream stream1 = c.stream();
       System.out.println(“stream1 = ” + stream1);

       // List 集合
       ArrayList list = new ArrayList<>();
       Stream stream2 = list.stream();
       System.out.println(“stream2 = ” + stream2);

       // Set 集合
       HashSet set = new HashSet<>();
       Stream stream3 = set.stream();
       System.out.println(“stream3 = ” + stream3);
  }
Map集合
   public static void main(String[] args) {

       // Map 集合
       HashMap

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值