Stream API
- 静态方法 Stream.of(1,2,3,4,5,6,7), Stream.generate(Math::random), Stream.iterate(0, (x)->x+3)
- stream()和parallelStream()并行流
- 处理文本中的每行 new BufferReader(“F://a.text”); text.lines(); streamx.forEach(System.out::println);
- 文本分隔,Pattern.compile(“,”);pattern.splitAsStream(“aeru,weruw,9ru,w”); stream.forEach(System.out::println);
- map 接收一个函数作为参数,该函数会作用到每个元素上面,并映射成一个新的元素
- flatMap: 接收一个函数作为参数, 将流中的每个值都换成另一个流,然后把所有流连接成一个流;
- 规约操作 reduce(BinaryOperator accumulator),accumulator参数的第一个参数为流中的第一个元素,第二个参数为第二个参数;第二次执行时,第一个参数为第一次执行的结果,第二个参数为第三个元素;依此类推;
- T reduce(T identity, BinaryOperator accumulator); 类似的,只是第一个参数为identity;