java8新特性从入门到应用 第二章 Streams数据流

2023-11-05

此流非彼流,估计第一眼看到这个标题的同学会将Streams当作InputStream或OutputStream 的兄弟,其实不然,Streams只是借用了流的概念,和原本的输入输出流是完全不同的东西。

本文代码及API部分转载自幸运的天才小驴

特点介绍

  1. Stream是对一系列集合进行操作的api
  2. 使用FunctionalInterface接口作为参数,可以直接使用Lambda,直观易懂
  3. Stream采用管道式api进行操作(指返回类型是类本身类型的方法,这类方法可以一直点下去从而省去中间声明命名等过程,使得写出来的代码更具可读性)。
  4. Stream的源可以是无限的(难以理解?其实就是根据设置一定的规则Stream将按规则 源源不断的生成数据)。
  5. Stream只能使用一次,当出现终端操作的时候Streams就会被消耗完(Stream不可复用)。
  6. Stream只循环一次,无论有多少中间操作。

你可以简单的将Stream的概念先理解成循环,然后在向下阅读,比较循环和Stream的异同,自然而然就可以学会了,(某些的大佬的解释是很严谨,但刚看时反而理解不上去)

Stream组成

Stream有3部分组成

  1. 源:指创建一个Stream的部分,有且只有一个
    相当于你想要循环的数据 比如你想循环一个数组,那么这个数组就是源
  2. 中间操作:指返回值是自己本身或另一个Stream的部分,可以有零到多个。
    相当于循环体,你想对循环的数据作什么,判断?、计算? 这都叫中间操作
  3. 终端:用于启动流的运行并产生结果或副作用。
    就是循环完成了你想干什么, 求和?查找? 这就是终端

指创建一个Stream,可以从多种数据类型中进行创建

  1. 直接创建
Stream stream=Stream.of("1","2","3");
Stream stream=Stream.generate(Math::random);
  1. 从Collection (List,Set) 中产生
Collection list=new ArrayList();
Stream stream=list.stream();
  1. 将数组转为Stream
String[] arr={"1","2","3"};
Stream stream=Stream.of(arr);
Stream stream=Arrays.stream(arr);

ps: 只要api支持很多类都可以直接转成 Stream

中间操作

所谓中间操作就是一系列Api的集合
`以下内容非原创 原文地址:幸运的天才小驴
多个 中间操作 可以连接起来形成一个流水线,除非流水 线上触发终止操作,否则中间操作不会执行任何的处理! 而在终止操作时一次性全部处理,称为“惰性求值”.

筛选与切片
方法 描述
filter(Predicate p) 从流中排除某些元素
distinct() 通过流元素的 hashCode() 和 equals() 对流进行去重
limit(long maxSize) 截断流,使其元素不超过给定数量
skip(long n) 跳过元素,返回一个扔掉了前 n 个元素的流。若流中元素 不足 n 个,则返回一个空流。与 limit(n) 互补

案例:

定义一个集合: Employee 重写 hashcode , equals — 去重时使用

List<Employee> emps = Arrays.asList(
          new Employee(101, "林青霞", 28, 9889.99),
          new Employee(102, "东方不败", 29, 4329.85),
          new Employee(103, "周星驰", 40, 1233.88),
          new Employee(104, "大圣", 500, 5000.44),
          new Employee(105, "张无忌", 15, 3000.09),
          new Employee(102, "东方不败", 29, 4329.85)
  );

执行操作:
内部迭代 - 迭代操作由Stream API 完成操作

public void test2() {
    // 中间操作不会做任何处理
    Stream<Employee> stream = emps.stream()
            .filter((e) -> {
                System.out.println("惰性求值");
                return e.getAge() < 30;
            });
    System.out.println("--------------------");

    // 终止操作,一次性执行全部功能, 称为 "惰性求值"
    stream.forEach(System.out::println);
}

执行结果:

--------------------
惰性求值
Employee{id=101, name='林青霞', age=28, salary=9889.99, status=null}
惰性求值
Employee{id=102, name='东方不败', age=29, salary=4329.85, status=null}
惰性求值
惰性求值
惰性求值
Employee{id=105, name='张无忌', age=15, salary=3000.09, status=null}
惰性求值
Employee{id=102, name='东方不败', age=29, salary=4329.85, status=null}

**外部迭代 **

@Test
public void test3() {
     Iterator<Employee> iterator = emps.iterator();

     while (iterator.hasNext()) {
         System.out.println(iterator.next());
     }
 }

执行结果:

Employee{id=101, name='林青霞', age=28, salary=9889.99, status=null}
Employee{id=102, name='东方不败', age=29, salary=4329.85, status=null}
Employee{id=103, name='周星驰', age=40, salary=1233.88, status=null}
Employee{id=104, name='大圣', age=500, salary=5000.44, status=null}
Employee{id=105, name='张无忌', age=15, salary=3000.09, status=null}
Employee{id=102, name='东方不败', age=29, salary=4329.85, status=null}

**中间操作 - 截断流 **

@Test
public void test4() {
     emps.stream()
             .filter(employee -> employee.getAge() < 30) // 过滤年龄小于30的人
             .limit(1) // 截取一个
             .forEach(System.out::println);
 }

执行结果:

Employee{id=101, name='林青霞', age=28, salary=9889.99, status=null}

**中间操作 - 跳过 ** ps: 不是让你跳过

@Test
public void test5() {

     emps.stream()
             .filter(employee -> employee.getAge() < 30)
             .skip(2)
             .forEach(System.out::println);
 }

执行结果:

Employee{id=105, name='张无忌', age=15, salary=3000.09, status=null}
Employee{id=102, name='东方不败', age=29, salary=4329.85, status=null}

**中间操作 - 筛选去重 **

@Test
public void test6() {
     emps.stream()
             .distinct()
             .forEach(System.out::println);
 }

执行结果:

Employee{id=101, name='林青霞', age=28, salary=9889.99, status=null}
Employee{id=102, name='东方不败', age=29, salary=4329.85, status=null}
Employee{id=103, name='周星驰', age=40, salary=1233.88, status=null}
Employee{id=104, name='大圣', age=500, salary=5000.44, status=null}
Employee{id=105, name='张无忌', age=15, salary=3000.09, status=null}
映射

只介绍map 其他4个和map大同小异

方法 描述
map(Function f) 接收一个函数作为参数,该函数会被应用到每个元 素上,并将其映射成一个新的元素。
mapToDouble(ToDoubleFunction f) 接收一个函数作为参数,该函数会被应用到每个元 素上,产生一个新的 DoubleStream。
mapToInt(ToIntFunction f) 接收一个函数作为参数,该函数会被应用到每个元 素上,产生一个新的 IntStream。
mapToLong(ToLongFunction f) 接收一个函数作为参数,该函数会被应用到每个元 素上,产生一个新的 LongStream。
flatMap(Function f) 接收一个函数作为参数,将流中的每个值都换成另一个流,然后把所有流连接成一个流

案例:
map操作

 public void test7() {
     List<String> list = Arrays.asList("aaa", "java", "ccc", "java8", "hello world");

     list.stream()
             .map((x) -> x.toUpperCase())
             .forEach(System.out::println);

     System.out.println("-------------");

     emps.stream()
             .map(Employee::getAge)
             .forEach(System.out::println);
 }

执行结果:

AAA
JAVA
CCC
JAVA8
HELLO WORLD
-------------
28
29
40
500
15
29

flatMap操作
先定义一个 filterCharacter(String str) 方法:

private static Stream<Character> filterCharacter(String str) {
        List<Character> characters = new ArrayList<>();

        for (Character character : str.toCharArray()) {
            characters.add(character);
        }
        return characters.stream();
    }

执行测试代码:

@Test
public void test8() {
    List<String> list = Arrays.asList("aaa", "hello world");

    Stream<Stream<Character>> streamStream = list.stream()
            .map(LambdaStramAPI::filterCharacter);

    streamStream.forEach((s) -> {
        s.forEach((c) -> System.out.println(c + ""));
        System.out.println();
    });

    System.out.println("----------------------");

    list.stream()
            .flatMap(LambdaStramAPI::filterCharacter)
            .forEach(System.out::println);


}

执行结果:

a
a
a

h
e
l
l
o

w
o
r
l
d

----------------------
a
a
a
h
e
l
l
o

w
o
r
l
d
排序
方法 描述
sorted() 产生一个新流,其中按自然顺序排序
sorted(Comparator comp) 产生一个新流,其中按比较器顺序排序

案例:

@Test
public void test9() {
    emps.stream()
            .map(Employee::getSalary)
            .sorted()
            .forEach(System.out::println);

    System.out.println("-----------------");

    emps.stream()
            .map(Employee::getAge)
            .sorted(Integer::compare)
            .forEach(System.out::println);
}

执行结果:

1233.88
3000.09
4329.85
4329.85
5000.44
9889.99
-----------------
15
28
29
29
40
500

Stream的终止操作

终止操作会从流的流水线生成结果。其结果可以是任何不是流的值,例如:List、Integer,甚至是 void 。

查找与匹配
方法 描述 结果
allMatch(Predicate p) 检查是否匹配所有元素 boolean
anyMatch(Predicate p) 检查是否至少匹配一个元素 boolean
noneMatch(Predicate p) 检查是否没有匹配所有元素 boolean
findFirst() 返回第一个元素 T
findAny() 返回当前流中的任意元素 T
count() 返回流中元素总数 long
max(Comparator c) 返回流中最大值 T
min(Comparator c) 返回流中最小值 T
forEach(Consumer c) 内部迭代(使用 Collection 接口需要用户去做迭 代,称为外部迭代。相反,Stream API 使用内部 迭代——它帮你把迭代做了) void

案例:
匹配

public void test10() {
    boolean allMatch = emps.stream()
            .allMatch((employee -> employee.getName().equals("林青霞")));
    System.out.println(allMatch);

    System.out.println("-----------------");

    boolean anyMatch = emps.stream()
            .anyMatch(employee -> employee.getName().equals("林青霞"));
    System.out.println(anyMatch);

    System.out.println("-----------------");

    boolean noneMatch = emps.stream()
            .noneMatch(employee -> employee.getName().equals("林青霞"));
    System.out.println(noneMatch);
}

执行结果:

false
-----------------
true
-----------------
false

**第一个元素 、 任意一个元素 **

public void test12() {
    Optional<String> first = emps.stream()
            .map(Employee::getName)
            .sorted()
            .findFirst(); // 获取第一个元素
    System.out.println(first.get());

    System.out.println("-----------------");

    Optional<Employee> findAny = emps.parallelStream()
            .filter(employee -> employee.getName().equals("林青霞"))
            .findAny(); //任意一个元素
    System.out.println(findAny.get());
}

执行结果:

东方不败
-----------------
Employee{id=101, name='林青霞', age=28, salary=9889.99, status=null}

**统计总个数、 最大、 最小值 **

public void test13() {
    Stream<Employee> stream = emps.stream();
    long count = stream.count();
    System.out.println(count);

    System.out.println("-----------------");

    Optional<Double> doubleOptional = emps.stream()
            .map(Employee::getSalary)
            .max(Double::compare); //最大值
    System.out.println(doubleOptional.get());

    System.out.println("-----------------");

    Optional<Employee> employeeOptional = emps.stream()
            .min((x, y) -> Double.compare(x.getSalary(),  y.getSalary())); // 最小值
    System.out.println(employeeOptional.get());
}

执行结果:

6
-----------------
9889.99
-----------------
Employee{id=103, name='周星驰', age=40, salary=1233.88, status=null}

归约

ps: map 和 reduce 的连接通常称为 map-reduce 模式,因 Google 用它 来进行网络搜索而出名。 --转载自幸运的天才小驴

方法 描述
reduce(T iden, BinaryOperator b) 可以将流中元素反复结合起来,得到一个值。 返回 T
reduce(BinaryOperator b) 可以将流中元素反复结合起来,得到一个值。 返回 Optional< T>

案例:
求和

@Test
public void test14() {
     List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

     Integer sum = list.stream()
             .reduce(0, (x, y) -> x + y);
     System.out.println(sum);
 }

执行结果:

55

计算次数

public void test15() {
    Optional<Double> doubleOptional = emps.stream()
            .map(Employee::getSalary)
            .reduce(Double::max);
    System.out.println(doubleOptional);

    System.out.println("-----------------");

    //查看 东方不败 出现的次数 -- 【此处还有点毛病】
    Optional<Integer> sumOptional = emps.stream()
            .map(Employee::getName)
            .flatMap(LambdaStramAPI::filterCharacter)
            .map((c) -> {
                if (c.equals("东")) return 1;
                else return 0;
            }).reduce(Integer::sum);
    System.out.println(sumOptional.get());
}

执行结果:

Optional[9889.99]
-----------------
0

收集

方法 描述
collect(Collector c) 将流转换为其他形式。接收一个 Collector接口的 实现,用于给Stream中元素做汇总的方法

案例:

public void test16(){
   List<String> collect = emps.stream()
           .map(Employee::getName)
           .collect(Collectors.toList());
   collect.forEach(System.out::println);

   System.out.println("-------------------");

   Set<String> set = emps.stream()
           .map(Employee::getName)
           .collect(Collectors.toSet());
   set.forEach(System.out::println);

   System.out.println("-------------------");

   HashSet<String> hashSet = emps.stream()
           .map(Employee::getName)
           .collect(Collectors.toCollection(HashSet::new));
   hashSet.forEach(System.out::println);
}

执行结果:

林青霞
东方不败
周星驰
大圣
张无忌
东方不败
-------------------
周星驰
林青霞
大圣
东方不败
张无忌
-------------------
周星驰
林青霞
大圣
东方不败
张无忌

**收集统计 **

 public  void test17(){
     // 统计总个数
     Long count = emps.stream()
             .collect(Collectors.counting());
     System.out.println(count);

     System.out.println("-------------------");

     // 求平均值
     Double avg = emps.stream()
             .collect(Collectors.averagingDouble(Employee::getSalary));
     System.out.println(avg);

     System.out.println("-------------------");

     // 求和
     Double sum = emps.stream()
             .collect(Collectors.summingDouble(Employee::getSalary));
     System.out.println(sum);

     System.out.println("-------------------");

     //求最大值
     Optional<Employee> max = emps.stream()
             .collect(Collectors.maxBy((x, y) -> Double.compare(x.getSalary(), y.getSalary())));
     System.out.println(max.get());

     System.out.println("-------------------");

     //求最小值
     Optional<Double> min = emps.stream()
             .map(Employee::getSalary)
             .collect(Collectors.minBy(Double::compare));
     System.out.println(min.get());


     System.out.println("-------------------");

     //统计分析
     DoubleSummaryStatistics doubleSummaryStatistics = emps.stream()
             .collect(Collectors.summarizingDouble(Employee::getSalary));
     System.out.println(doubleSummaryStatistics.getAverage());

     System.out.println("-------------------");

     //拼接
     String join = emps.stream()
             .map(Employee::getName)
             .collect(Collectors.joining(",", "--", "--"));
     System.out.println(join);
 }

执行结果:

6
-------------------
4630.683333333333
-------------------
27784.1
-------------------
Employee{id=101, name='林青霞', age=28, salary=9889.99, status=null}
-------------------
1233.88
-------------------
4630.683333333333
-------------------
--林青霞,东方不败,周星驰,大圣,张无忌,东方不败--

**收集-分组 **

public  void test18(){
    Map<String, List<Employee>> group = emps.stream()
            .collect(Collectors.groupingBy(Employee::getName));
    System.out.println(group);
}

执行结果:

{
周星驰=[Employee{id=103, name='周星驰', age=40, salary=1233.88, status=null}], 
林青霞=[Employee{id=101, name='林青霞', age=28, salary=9889.99, status=null}], 
大圣=[Employee{id=104, name='大圣', age=500, salary=5000.44, status=null}], 
东方不败=[
Employee{id=102, name='东方不败', age=29, salary=4329.85, status=null}, 
Employee{id=102, name='东方不败', age=29, salary=4329.85, status=null}
], 
张无忌=[Employee{id=105, name='张无忌', age=15, salary=3000.09, status=null}]}

**收集-多级分组 **

public void test19(){
    Map<String, Map<String, List<Employee>>> group = emps.stream()
            .collect(Collectors.groupingBy(Employee::getName, Collectors.groupingBy((e) -> {
                if (e.getAge() < 30) return "青年";
                else if (e.getAge() < 50) return "中年";
                else return "老年";
            })));
    System.out.println(group);
}

执行结果:

{周星驰={中年=[Employee{id=103, name='周星驰', age=40, salary=1233.88, status=null}]}, 
林青霞={青年=[Employee{id=101, name='林青霞', age=28, salary=9889.99, status=null}]}, 
大圣={老年=[Employee{id=104, name='大圣', age=500, salary=5000.44, status=null}]}, 
东方不败={青年=[
Employee{id=102, name='东方不败', age=29, salary=4329.85, status=null}, 
Employee{id=102, name='东方不败', age=29, salary=4329.85, status=null}
]}, 
张无忌={青年=[Employee{id=105, name='张无忌', age=15, salary=3000.09, status=null}]}}

Collector 接口中方法的实现决定了如何对流执行收集操作(如收 集到 List、Set、Map)。但是 Collectors 实用类 供了很多静态 方法,可以方便地创建常见收集器实例,具体方法与实例如下表:

Collector 接口API
方法 返回类型 作用
toList List 把流中元素收集到List
toSet Set 把流中元素收集到Set
toCollection Collection 把流中元素收集到Set
counting Long 计算流中元素的个数
summingInt Integer 对流中元素的整数属性求和
averagingInt Double 计算流中元素Integer属性的平均 值
summarizingInt IntSummaryStatistics 收集流中Integer属性的统计值。 如:平均值
joining String 连接流中每个字符串
maxBy Optional 根据比较器选择最大值
minBy Optional 根据比较器选择最小值
reducing 归约产生的类型 从一个作为累加器的初始值 开始,利用BinaryOperator与 流中元素逐个结合,从而归 约成单个值
collectingAndThen 转换函数返回的类型 包裹另一个收集器,对其结 果转换函数
groupingBy Map<K, List> 根据某属性值对流分组,属 性为K,结果为V
partitioningBy Map<Boolean, List> 根据true或false进行分组
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

java8新特性从入门到应用 第二章 Streams数据流 的相关文章

随机推荐

  • ajax请求路径正确,可是页面提示404错误。

    2019独角兽企业重金招聘Python工程师标准 gt gt gt 昨晚项目升级 开发环境 测试环境一切OK 一上线 页面空白 页面console打印404 查看后台日志报如下错误 Illegal mix of collations utf
  • 简述 Redis 的 安装 /持久化策略/内存策略/分片机制/哨兵机制/集群配置

    Redis 简介 Redis 是一种开源的 内存中的数据结构存储系统 它可以用作数据库 缓存和消息中间件 它支持多种类型的数据结构 如 字符串 strings 散列 hashes 列表 lists 集合 sets 有序集合 sorted s
  • win7系统中装Ubuntu系统

    结合网上经验亲自安装测试通过 故整理备用 一 分离磁盘空间 1 1 选中桌面计算机图标 gt 右键选择 管理 打开磁盘管理 1 2 以D盘为例 分离出50G左右磁盘空间 选中D盘 右键选择 压缩卷 输入需要分离出的磁盘空间 点击 压缩 完成
  • 在极高负荷情况下oracle redolog的配置建议

    在极高负荷情况下oracle redolog的配置建议 在oracle数据库的现有体系结构下 redolog承担了很大的压力 这是因为所有提交给数据库的交易都需要在commite确认前通过LGWR进程将相关信息写入redolog 而一个or
  • 关于我查找了很多资料仍不知道为何不能通过npm安装引入echarts和不能直接引入echarts.js文件这档事。

    通过几番周折 明白了如何通过nodejs下载echarts 包括解决 通过几番周折 明白了如何通过nodejs下载echarts 包括解决这个东西 感觉还是挺有趣的 然后就打算用这种方式来引入了 毕竟已经花了一定时间在上面 网上继续查找资料
  • access按职称计算平均年龄_2012年计算机二级Access考前模拟题及答案(5)

    一 基本操作题 在考生文件夹下 已有 samp1 mdb 数据库文件和Stab xls文件 samp1 mdb 中已建立表对象 student 和 grade 试按以下要求 完成表的各种操作 1 将考生文件夹下的Stab xls文件导入到
  • 中国14岁初中生,开源Windows 12网页版,star数近2k

    出品 OSC开源社区 ID oschina2013 最近在网上冲浪 发现名为 Windows 12 网页版 的开源项目 在网页端实现了 Windows 12 的交互和 UI 项目亮点 精美的 UI 设计 流畅丰富的动画 各种高级的功能 相较
  • 解决Ubuntu 14.04 built-in display 分辨率较低的方法

    打开终端 输入 sudo nona etc X11 xorg conf 将下列代码粘贴复制到终端 Section Monitor Identifier Monitor0 VendorName Monitor Vendor ModelName
  • http://www.msftconnecttest.com/redirect找不到应用程序解决办法

    我在连学校内网的时候 不能自动跳转到登录的页面 因为有一些默认的配置已经被修改 可能有的人认为不是自己修改的 那么原因也有可能是软件安装的过程中默认设置被修改 也有可能是你不轻易间点错了 不废话了 直接发图 第一步 window10 点击左
  • epoll全面讲解:从实现到应用

    epoll全面讲解 从实现到应用 什么是epoll 或者说 它和select有什么区别 什么是select 有的朋友可能对select也不是很了解啊 我这里稍微科普一下 网络连接 服务器也是通过文件描述符来管理这些连接上来的客户端 既然是供
  • 使用 getopt() 进行命令行处理

    使用 getopt 进行命令行处理 轻松处理复杂命令行 文档选项 打印本页 将此页作为电子邮件发送 样例代码 级别 中级 Chris Herborth chrish pobox com 自由撰稿人 作家 2006 年 5 月 25 日 所有
  • 只需单击三次,让中文GPT-2为你生成定制故事

    2019 11 12 12 49 55 机器之心报道 机器之心编辑部 想要 GPT 2 生成中文故事 听听它对各种主题的看法 你可以试试这个中文预训练 GPT 2 项目 它开源了预训练结果与 Colab Demo 演示 只需要单击三次 我们
  • QSettings读取int文件解析失败

    问题 QSettings解析失败 ini文件如下 System name CPMS with IIoT by R Campro Precision Machinery Co Ltd gs sys id CAMPRO gs cod csub
  • AI引擎助力,CamScanner智能高清滤镜开启扫描新纪元!

    文章目录 写在前面 突破图像处理难点 扫描全能王的独特优势 耳听为虚 眼见为实 产品背后的主要核心 AI Scan助力 深度学习助力智能文档处理的国际化进程 品味智能文档处理的轻松与精准 写在前面 在数字化快速发展的今天 我们时常会遇到需要
  • 产品经理漫谈四

    每几天一篇 业界学习知识分享 请关注 如有同感请加vip阅读 产品经理如何给足一线 渠道 区域销售足够信心 思考 人性 商业 利益共同体 尊重时效 尊重承诺 价值方向 行业动态符合 具有更大兼容性 服务体系建立 笔者认为 除了产品包含市场方
  • 芯片验证从零开始系列(三)——SystemVerilog的连接设计和测试平台

    芯片验证从零开始系列 三 SystemVerilog的连接设计和测试平台 接口interface modport 验证环境结构 激励发生器 监测器 检测器 测试平台和设计间的竞争原因 断言 总结 声明 未经作者允许 禁止转载 推荐一个IC
  • AD域服务器下如何批量创建用户及修改AD域的最大返回条目数。

    最近在用户现场遇到一个问题就是通过ldap导入用户 发现导入失败 经过分析得知是AD域服务器设置的最大返回条目数默认为1000 当数据超过1000 通过ldap search s获取数据时就会异常 通过抓包分析得知是 报文回复不全导致无法解
  • 史上最全 App功能测试点分析

    1 2测试周期 测试周期可按项目的开发周期来确定测试时间 一般测试时间为两三周 即 15个工作日 根据项目情况以及版本质量可适当缩短或延长测试时间 正式测试前先向主管确认项目排期 1 3测试资源 测试任务开始前 检查各项测试资源 产品功能需
  • [k8s]笔记01

    1 k8s是什么 k8s是一套自动化容器运维的开源平台 2 k8s可以做什么 能在物理机或虚拟集群上调度和运行程序容器 快速精准地部署应用程序 即时伸缩应用程序 无缝展现新特征 限制硬件用量仅为所需资源 3 k8s概念 1 Cluster集
  • java8新特性从入门到应用 第二章 Streams数据流

    java8新特性从入门到应用 第二章 Stream 数据流 特点介绍 Stream组成 源 中间操作 筛选与切片 映射 排序 Stream的终止操作 查找与匹配 归约 收集 Collector 接口API 此流非彼流 估计第一眼看到这个标题