StreamSupport (Java SE 13 & JDK 13 )
public final class StreamSupport extends Object
Low-level utility methods for creating and manipulating streams.
This class is mostly for library writers presenting stream views
of data structures; most static stream methods intended for end users are in
the various Stream classes.
- Since:
- 1.8
-
Method Summary
Modifier and Type Method Description static DoubleStreamdoubleStream(Supplier<? extends Spliterator.OfDouble> supplier, int characteristics, boolean parallel)Creates a new sequential or parallel
DoubleStreamfrom aSupplierofSpliterator.OfDouble.static DoubleStreamdoubleStream(Spliterator.OfDouble spliterator, boolean parallel)Creates a new sequential or parallel
DoubleStreamfrom aSpliterator.OfDouble.static IntStreamintStream(Supplier<? extends Spliterator.OfInt> supplier, int characteristics, boolean parallel)Creates a new sequential or parallel
IntStreamfrom aSupplierofSpliterator.OfInt.static IntStreamintStream(Spliterator.OfInt spliterator, boolean parallel)Creates a new sequential or parallel
IntStreamfrom aSpliterator.OfInt.static LongStreamlongStream(Supplier<? extends Spliterator.OfLong> supplier, int characteristics, boolean parallel)Creates a new sequential or parallel
LongStreamfrom aSupplierofSpliterator.OfLong.static LongStreamlongStream(Spliterator.OfLong spliterator, boolean parallel)Creates a new sequential or parallel
LongStreamfrom aSpliterator.OfLong.static <T> Stream<T>stream(Supplier<? extends Spliterator<T>> supplier, int characteristics, boolean parallel)Creates a new sequential or parallel
Streamfrom aSupplierofSpliterator.static <T> Stream<T>stream(Spliterator<T> spliterator, boolean parallel)Creates a new sequential or parallel
Streamfrom aSpliterator.
-
Method Details
-
stream
public static <T> Stream<T> stream(Spliterator<T> spliterator, boolean parallel)
Creates a new sequential or parallel
Streamfrom aSpliterator.The spliterator is only traversed, split, or queried for estimated size after the terminal operation of the stream pipeline commences.
It is strongly recommended the spliterator report a characteristic of
IMMUTABLEorCONCURRENT, or be late-binding. Otherwise,stream(java.util.function.Supplier, int, boolean)should be used to reduce the scope of potential interference with the source. See Non-Interference for more details.- Type Parameters:
T- the type of stream elements- Parameters:
spliterator- aSpliteratordescribing the stream elementsparallel- iftruethen the returned stream is a parallel stream; iffalsethe returned stream is a sequential stream.- Returns:
- a new sequential or parallel
Stream
-
stream
public static <T> Stream<T> stream(Supplier<? extends Spliterator<T>> supplier, int characteristics, boolean parallel)
Creates a new sequential or parallel
Streamfrom aSupplierofSpliterator.The
Supplier.get()method will be invoked on the supplier no more than once, and only after the terminal operation of the stream pipeline commences.For spliterators that report a characteristic of
IMMUTABLEorCONCURRENT, or that are late-binding, it is likely more efficient to usestream(java.util.Spliterator, boolean)instead.The use of a
Supplierin this form provides a level of indirection that reduces the scope of potential interference with the source. Since the supplier is only invoked after the terminal operation commences, any modifications to the source up to the start of the terminal operation are reflected in the stream result. See Non-Interference for more details.- Type Parameters:
T- the type of stream elements- Parameters:
supplier- aSupplierof aSpliteratorcharacteristics- Spliterator characteristics of the suppliedSpliterator. The characteristics must be equal tosupplier.get().characteristics(), otherwise undefined behavior may occur when terminal operation commences.parallel- iftruethen the returned stream is a parallel stream; iffalsethe returned stream is a sequential stream.- Returns:
- a new sequential or parallel
Stream - See Also:
stream(java.util.Spliterator, boolean)
-
intStream
Creates a new sequential or parallel
IntStreamfrom aSpliterator.OfInt.The spliterator is only traversed, split, or queried for estimated size after the terminal operation of the stream pipeline commences.
It is strongly recommended the spliterator report a characteristic of
IMMUTABLEorCONCURRENT, or be late-binding. Otherwise,intStream(java.util.function.Supplier, int, boolean)should be used to reduce the scope of potential interference with the source. See Non-Interference for more details.- Parameters:
spliterator- aSpliterator.OfIntdescribing the stream elementsparallel- iftruethen the returned stream is a parallel stream; iffalsethe returned stream is a sequential stream.- Returns:
- a new sequential or parallel
IntStream
-
intStream
Creates a new sequential or parallel
IntStreamfrom aSupplierofSpliterator.OfInt.The
Supplier.get()method will be invoked on the supplier no more than once, and only after the terminal operation of the stream pipeline commences.For spliterators that report a characteristic of
IMMUTABLEorCONCURRENT, or that are late-binding, it is likely more efficient to useintStream(java.util.Spliterator.OfInt, boolean)instead.The use of a
Supplierin this form provides a level of indirection that reduces the scope of potential interference with the source. Since the supplier is only invoked after the terminal operation commences, any modifications to the source up to the start of the terminal operation are reflected in the stream result. See Non-Interference for more details.- Parameters:
supplier- aSupplierof aSpliterator.OfIntcharacteristics- Spliterator characteristics of the suppliedSpliterator.OfInt. The characteristics must be equal tosupplier.get().characteristics(), otherwise undefined behavior may occur when terminal operation commences.parallel- iftruethen the returned stream is a parallel stream; iffalsethe returned stream is a sequential stream.- Returns:
- a new sequential or parallel
IntStream - See Also:
intStream(java.util.Spliterator.OfInt, boolean)
-
longStream
Creates a new sequential or parallel
LongStreamfrom aSpliterator.OfLong.The spliterator is only traversed, split, or queried for estimated size after the terminal operation of the stream pipeline commences.
It is strongly recommended the spliterator report a characteristic of
IMMUTABLEorCONCURRENT, or be late-binding. Otherwise,longStream(java.util.function.Supplier, int, boolean)should be used to reduce the scope of potential interference with the source. See Non-Interference for more details.- Parameters:
spliterator- aSpliterator.OfLongdescribing the stream elementsparallel- iftruethen the returned stream is a parallel stream; iffalsethe returned stream is a sequential stream.- Returns:
- a new sequential or parallel
LongStream
-
longStream
Creates a new sequential or parallel
LongStreamfrom aSupplierofSpliterator.OfLong.The
Supplier.get()method will be invoked on the supplier no more than once, and only after the terminal operation of the stream pipeline commences.For spliterators that report a characteristic of
IMMUTABLEorCONCURRENT, or that are late-binding, it is likely more efficient to uselongStream(java.util.Spliterator.OfLong, boolean)instead.The use of a
Supplierin this form provides a level of indirection that reduces the scope of potential interference with the source. Since the supplier is only invoked after the terminal operation commences, any modifications to the source up to the start of the terminal operation are reflected in the stream result. See Non-Interference for more details.- Parameters:
supplier- aSupplierof aSpliterator.OfLongcharacteristics- Spliterator characteristics of the suppliedSpliterator.OfLong. The characteristics must be equal tosupplier.get().characteristics(), otherwise undefined behavior may occur when terminal operation commences.parallel- iftruethen the returned stream is a parallel stream; iffalsethe returned stream is a sequential stream.- Returns:
- a new sequential or parallel
LongStream - See Also:
longStream(java.util.Spliterator.OfLong, boolean)
-
doubleStream
Creates a new sequential or parallel
DoubleStreamfrom aSpliterator.OfDouble.The spliterator is only traversed, split, or queried for estimated size after the terminal operation of the stream pipeline commences.
It is strongly recommended the spliterator report a characteristic of
IMMUTABLEorCONCURRENT, or be late-binding. Otherwise,doubleStream(java.util.function.Supplier, int, boolean)should be used to reduce the scope of potential interference with the source. See Non-Interference for more details.- Parameters:
spliterator- ASpliterator.OfDoubledescribing the stream elementsparallel- iftruethen the returned stream is a parallel stream; iffalsethe returned stream is a sequential stream.- Returns:
- a new sequential or parallel
DoubleStream
-
doubleStream
Creates a new sequential or parallel
DoubleStreamfrom aSupplierofSpliterator.OfDouble.The
Supplier.get()method will be invoked on the supplier no more than once, and only after the terminal operation of the stream pipeline commences.For spliterators that report a characteristic of
IMMUTABLEorCONCURRENT, or that are late-binding, it is likely more efficient to usedoubleStream(java.util.Spliterator.OfDouble, boolean)instead.The use of a
Supplierin this form provides a level of indirection that reduces the scope of potential interference with the source. Since the supplier is only invoked after the terminal operation commences, any modifications to the source up to the start of the terminal operation are reflected in the stream result. See Non-Interference for more details.- Parameters:
supplier- ASupplierof aSpliterator.OfDoublecharacteristics- Spliterator characteristics of the suppliedSpliterator.OfDouble. The characteristics must be equal tosupplier.get().characteristics(), otherwise undefined behavior may occur when terminal operation commences.parallel- iftruethen the returned stream is a parallel stream; iffalsethe returned stream is a sequential stream.- Returns:
- a new sequential or parallel
DoubleStream - See Also:
doubleStream(java.util.Spliterator.OfDouble, boolean)
-
Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2019, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.