从底层重学 Java 之 Stream 初探 Gitchat连接

Gitchat连接

https://gitbook.cn/gitchat/activity/5f85696aad812d16b498848c

简介

从底层,从原理,我们来重学一次 Java。Stream 是JDK8中新引入的,方便了数据列表的过滤、投影、遍历等各种处理,他的源码及实现是怎样的呢?

本系列秉承所有结论尽量从源码中来,没有源码的尽量标明出处。相关源码会附着在文章中,读本文即可,不用再自行查找源码及资料学习,方便大家充分利用路上的碎片时间。

本篇 Chat 从Stream示例开始,讲解构建Stream源码,分析了非并行forEach各种情况的源码逻辑,讲解了Stream的各个接口及应用示例,帮助大家深入理解和学习 JDK 源码。

本文包含以下内容:

  • 列表获取流
    • Collection.stream()
  • 数组获取流
    • Arrays.stream(T[] array)
    • Arrays.stream(T[] array, int startInclusive, int endExclusive)
  • 直接构建流
    • Stream.of
  • StreamSupport
    • 构造函数
    • stream(Spliterator spliterator, boolean parallel)
  • Collection.spliterator()
    • fail-fast快速失败机制
  • 非并行forEach
    • stream直接进行forEach
      • Arrays.stream的forEach
        • Arrays.spliterator(T[] array, int startInclusive, int endExclusive)
        • Spliterators.spliterator(Object[] array, int fromIndex, int toIndex, int additionalCharacteristics)
        • ArraySpliterator.forEachRemaining(Consumer<? super T> action)
        • 总结
      • ArrayList stream的forEach
        • Collection.stream()
        • ArrayList.spliterator()
        • ArrayList.ArrayListSpliterator
        • ArrayList.ArrayListSpliterator.forEachRemaining
        • 总结
    • stream进行一次中间操作再forEach
      • ReferencePipeline.filter
      • ReferencePipeline.StatelessOp
      • ReferencePipeline.forEach
      • ForEachOps
      • ForEachOps.makeRef(Consumer<? super T> action, boolean ordered)
        • ForEachOp
        • ForEachOp.OfRef
      • AbstractPipeline.evaluate
      • ForEachOps.ForEachOp.evaluateSequential
      • AbstractPipeline.wrapAndCopyInto
      • AbstractPipeline.wrapSink
      • AbstractPipeline.copyInto
      • Sink.ChainedReference
      • 总结
  • Stream
    • 接口定义
    • 接口继承结构
    • filter(Predicate<? super T> predicate)
    • map(Function<? super T, ? extends R> mapper)
    • mapToInt(ToIntFunction<? super T> mapper)
    • mapToLong(ToLongFunction<? super T> mapper)
    • mapToDouble(ToDoubleFunction<? super T> mapper)
    • flatMap(Function<? super T, ? extends Stream<? extends R>> mapper)
    • flatMapToInt(Function<? super T, ? extends IntStream> mapper)
    • flatMapToLong(Function<? super T, ? extends LongStream> mapper)
    • flatMapToDouble(Function<? super T, ? extends DoubleStream> mapper)
    • distinct()
    • sorted()
    • sorted(Comparator<? super T> comparator)
    • peek(Consumer<? super T> action)
    • limit(long maxSize)
    • skip(long n)
    • forEach(Consumer<? super T> action)
    • forEachOrdered(Consumer<? super T> action)
    • toArray(IntFunction<A[]> generator)
    • reduce(T identity, BinaryOperator accumulator)
    • reduce(BinaryOperator accumulator)
    • reduce(U identity,BiFunction<U, ? super T, U> accumulator,BinaryOperator<U> combiner)
      • 调用示例1
      • 调用示例2
      • 调用示例3
    • collect(Supplier<R> supplier, BiConsumer<R, ? super T> accumulator, BiConsumer<R, R> combiner)
      • 调用示例1
      • 调用示例2
      • 调用示例3
    • collect(Collector<? super T, A, R> collector)
      • 流转List示例
      • GroupBy分组示例
    • min(Comparator<? super T> comparator)
    • max(Comparator<? super T> comparator)
    • count()
    • anyMatch(Predicate<? super T> predicate)
      • 调用示例1
      • 调用示例2
    • allMatch(Predicate<? super T> predicate)
      • 调用示例1
      • 调用示例2
    • noneMatch(Predicate<? super T> predicate)
      • 调用示例1
      • 调用示例2
    • findFirst()
    • findAny()
    • builder()
    • empty()
    • of(T t)
    • Stream<T> of(T… values)
    • iterate(final T seed, final UnaryOperator<T> f)
      • Streams.NONE
      • Spliterators.spliteratorUnknownSize(Iterator<? extends T> iterator, int characteristics)
      • 调用示例
    • generate(Supplier s)
      • StreamSpliterators
      • StreamSpliterators.InfiniteSupplyingSpliterator
      • StreamSpliterators.InfiniteSupplyingSpliterator.OfRef<T>
      • 调用示例
    • concat(Stream<? extends T> a, Stream<? extends T> b)
      • Streams.composedClose(BaseStream<?, ?> a, BaseStream<?, ?> b)
      • Throwable.addSuppressed(Throwable exception)
      • Throwable.SUPPRESSED_SENTINEL
      • Throwable.suppressedExceptions
  • Stream.Builder
    • accept(T t)
    • add(T t)
    • build()
  • BaseStream
    • 接口定义
    • 接口继承结构
  • AutoCloseable
    • 接口定义
    • 接口继承结构
    • close()
    • try-with-resources

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/416649.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

签到题

直接查看源代码 nctf{flag_admiaanaaaaaaaaaaa}转载于:https://www.cnblogs.com/maodun/p/6912628.html

从底层重学 Java 之 Stream 并行及标志 GitChat连接

GitChat连接 https://gitbook.cn/gitchat/activity/5f8fc6cd1f577d4d9f428562 简介 从底层&#xff0c;从原理&#xff0c;我们来重学一次 Java。Stream 是JDK8中新引入的&#xff0c;方便了数据列表的过滤、投影、遍历等各种处理&#xff0c;他的源码及实现是怎样的呢&…

工作总结16:多看官网

多看官网 https://cn.vuejs.org/v2/guide/components.html

201521123121 《Java程序设计》第14周学习总结

1. 本周学习总结 1.1 以你喜欢的方式&#xff08;思维导图或其他&#xff09;归纳总结多数据库相关内容。 数据库的基本特点 1、实现数据共享 数据共享包含所有用户可同时存取数据库中的数据&#xff0c;也包括用户可以用各种方式通过接口使用数据库&#xff0c;并提供数据共享…

Java操作Mongo bulkWrite批量入库

Mongo bulkWrite示例 public boolean insertBulk(String collectionName, JSONArray array) {MongoCollection<Document> collection db.getCollection(collectionName);List<InsertOneModel<Document>> documentList array.stream().map(item -> {Doc…

工作总结17:组件封装思想

就是把部门下拉框选择这部分变成一个组件&#xff0c;在用户创建的时候引入这样就可以把功能不相关代码模块化&#xff0c;以后也便于管理如果别的地方也要用到部门选择&#xff0c;可以直接再次引入&#xff0c;就不用重复写代码了

c#程序中使用quot;like“查询access数据库查询为空的问题

今天&#xff0c;在开发的过程中发现了一个特别奇怪的问题&#xff1a;access中like查询时候。在Access数据库中运行&#xff0c;发现能够查询出结果。这是在数据库上运行。select * from KPProj where KpName like *測试*&#xff0c;可是相同的语句在c#程序中却查询为空。这是…

SpringBoot启动yaml报错

报错找不到org.yaml里的一个方法 10:45:54.742 [main] ERROR org.springframework.boot.SpringApplication - Application run failed java.lang.NoSuchMethodError: org.yaml.snakeyaml.nodes.ScalarNode.getScalarStyle()Lorg/yaml/snakeyaml/DumperOptions$ScalarStyle;at …

JS中的预编译(词法分析)阶段和执行阶段

javascript相对于其它语言来说是一种弱类型的语言&#xff0c;在其它如java语言中&#xff0c;程序的执行需要有编译的阶段&#xff0c;而在javascript中也有类似的“预编译阶段”&#xff08;javascript的预编译是以代码块为范围<script></script>&#xff0c;即每…

Excel分组最大级别为8(outlineLevel最大为7)

excel分组最大级别为8&#xff0c;超过则会删除。 事故现场 Java操作POI分组超过7级&#xff08;算上末级节点&#xff0c;一共8级&#xff09;&#xff0c; 分组作用在sheetData节点下row节点的outlineLevel上&#xff0c;一级分组没有该属性&#xff0c;2-8级分组该值对应为…

Java 的Tuple(类似.net等的元组)

commons-lang3包 两个参数&#xff1a;MutablePair&#xff08;可修改&#xff09;、ImmutablePair&#xff0c;三个参数&#xff1a;MutableTriple&#xff08;可修改&#xff09;、ImmutableTriple&#xff08;不可修改&#xff09; 包commons-lang3 3.8.1里就有 org/apach…

day02-java关键字

转载于:https://www.cnblogs.com/tantanba/p/6917959.html

JacksonUtils Jackson的JSON序列化反序列化

pom.xml添加依赖 <dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>2.11.3</version> </dependency>公共方法 import com.fasterxml.jackson.core.JsonProces…

工作总结8:关于Vue中的slot-scope=“scope“

<template><el-table :data"tableData" style"width: 100%">//---:data"用于存放请求数据回来的数组"<el-table-column label"索引值" width"400"><template slot-scope"scope">//--- 这…

文本

文本样式&#xff1a; color       设置字体颜色 text-align    元素水平对齐方式 text-indent   首行文本的缩进 "em"或"px" line-height    文本的行高 text-decoration 文本的装饰  对齐方式&#xff1a; 水平对齐方式&#xff1a; t…

maven打包报错You have to use a classifier to attach supplemental artifacts to the project instead of rep

maven打包报错You have to use a classifier to attach supplemental artifacts to the project instead of replacing them. [WARNING]JAR will be empty - no content was marked for inclusion!15:51:40 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-ja…

第一次绩效评估

评估结果如下&#xff1a; 第一名&#xff1a;谢梦雨 第二名&#xff1a;田会 第三名&#xff1a;王凤彬 第四名&#xff1a;张贺转载于:https://www.cnblogs.com/xtwz/p/7025874.html