从底层重学 Java 之 Stream 初探 Gitchat连接
生活随笔
收集整理的這篇文章主要介紹了
从底层重学 Java 之 Stream 初探 Gitchat连接
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Gitchat連接
https://gitbook.cn/gitchat/activity/5f85696aad812d16b498848c
簡介
從底層,從原理,我們來重學(xué)一次 Java。Stream 是JDK8中新引入的,方便了數(shù)據(jù)列表的過濾、投影、遍歷等各種處理,他的源碼及實(shí)現(xiàn)是怎樣的呢?
本系列秉承所有結(jié)論盡量從源碼中來,沒有源碼的盡量標(biāo)明出處。相關(guān)源碼會(huì)附著在文章中,讀本文即可,不用再自行查找源碼及資料學(xué)習(xí),方便大家充分利用路上的碎片時(shí)間。
本篇 Chat 從Stream示例開始,講解構(gòu)建Stream源碼,分析了非并行forEach各種情況的源碼邏輯,講解了Stream的各個(gè)接口及應(yīng)用示例,幫助大家深入理解和學(xué)習(xí) JDK 源碼。
本文包含以下內(nèi)容:
- 列表獲取流
- Collection.stream()
- 數(shù)組獲取流
- Arrays.stream(T[] array)
- Arrays.stream(T[] array, int startInclusive, int endExclusive)
- 直接構(gòu)建流
- Stream.of
- StreamSupport
- 構(gòu)造函數(shù)
- stream(Spliterator spliterator, boolean parallel)
- Collection.spliterator()
- fail-fast快速失敗機(jī)制
- 非并行forEach
- stream直接進(jìn)行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)
- 總結(jié)
- ArrayList stream的forEach
- Collection.stream()
- ArrayList.spliterator()
- ArrayList.ArrayListSpliterator
- ArrayList.ArrayListSpliterator.forEachRemaining
- 總結(jié)
- Arrays.stream的forEach
- stream進(jìn)行一次中間操作再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
- 總結(jié)
- stream直接進(jìn)行forEach
- Stream
- 接口定義
- 接口繼承結(jié)構(gòu)
- 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)
- 調(diào)用示例1
- 調(diào)用示例2
- 調(diào)用示例3
- collect(Supplier<R> supplier, BiConsumer<R, ? super T> accumulator, BiConsumer<R, R> combiner)
- 調(diào)用示例1
- 調(diào)用示例2
- 調(diào)用示例3
- collect(Collector<? super T, A, R> collector)
- 流轉(zhuǎn)List示例
- GroupBy分組示例
- min(Comparator<? super T> comparator)
- max(Comparator<? super T> comparator)
- count()
- anyMatch(Predicate<? super T> predicate)
- 調(diào)用示例1
- 調(diào)用示例2
- allMatch(Predicate<? super T> predicate)
- 調(diào)用示例1
- 調(diào)用示例2
- noneMatch(Predicate<? super T> predicate)
- 調(diào)用示例1
- 調(diào)用示例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)
- 調(diào)用示例
- generate(Supplier s)
- StreamSpliterators
- StreamSpliterators.InfiniteSupplyingSpliterator
- StreamSpliterators.InfiniteSupplyingSpliterator.OfRef<T>
- 調(diào)用示例
- 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
- 接口定義
- 接口繼承結(jié)構(gòu)
- AutoCloseable
- 接口定義
- 接口繼承結(jié)構(gòu)
- close()
- try-with-resources
總結(jié)
以上是生活随笔為你收集整理的从底层重学 Java 之 Stream 初探 Gitchat连接的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: withMisfireHandlingI
- 下一篇: 请问smartadmin中如何只用其tr