Class StreamSupport
- java.lang.Object
-
- java.util.stream.StreamSupport
-
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
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static DoubleStream
doubleStream(Spliterator.OfDouble spliterator, boolean parallel)
Creates a new sequential or parallelDoubleStream
from aSpliterator.OfDouble
.static DoubleStream
doubleStream(Supplier<? extends Spliterator.OfDouble> supplier, int characteristics, boolean parallel)
Creates a new sequential or parallelDoubleStream
from aSupplier
ofSpliterator.OfDouble
.static IntStream
intStream(Spliterator.OfInt spliterator, boolean parallel)
Creates a new sequential or parallelIntStream
from aSpliterator.OfInt
.static IntStream
intStream(Supplier<? extends Spliterator.OfInt> supplier, int characteristics, boolean parallel)
Creates a new sequential or parallelIntStream
from aSupplier
ofSpliterator.OfInt
.static LongStream
longStream(Spliterator.OfLong spliterator, boolean parallel)
Creates a new sequential or parallelLongStream
from aSpliterator.OfLong
.static LongStream
longStream(Supplier<? extends Spliterator.OfLong> supplier, int characteristics, boolean parallel)
Creates a new sequential or parallelLongStream
from aSupplier
ofSpliterator.OfLong
.static <T> Stream<T>
stream(Spliterator<T> spliterator, boolean parallel)
Creates a new sequential or parallelStream
from aSpliterator
.static <T> Stream<T>
stream(Supplier<? extends Spliterator<T>> supplier, int characteristics, boolean parallel)
Creates a new sequential or parallelStream
from aSupplier
ofSpliterator
.
-
-
-
Method Detail
stream
public static <T> Stream<T> stream(Spliterator<T> spliterator, boolean parallel)
Creates a new sequential or parallelStream
from 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
IMMUTABLE
orCONCURRENT
, 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
- aSpliterator
describing the stream elements -
parallel
- iftrue
then the returned stream is a parallel stream; iffalse
the 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 parallelStream
from aSupplier
ofSpliterator
.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
IMMUTABLE
orCONCURRENT
, or that are late-binding, it is likely more efficient to usestream(java.util.Spliterator, boolean)
instead.The use of a
Supplier
in 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
- aSupplier
of aSpliterator
-
characteristics
- Spliterator characteristics of the suppliedSpliterator
. The characteristics must be equal tosupplier.get().characteristics()
, otherwise undefined behavior may occur when terminal operation commences. -
parallel
- iftrue
then the returned stream is a parallel stream; iffalse
the returned stream is a sequential stream. - Returns:
-
a new sequential or parallel
Stream
- See Also:
-
stream(java.util.Spliterator, boolean)
intStream
public static IntStream intStream(Spliterator.OfInt spliterator, boolean parallel)
Creates a new sequential or parallelIntStream
from 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
IMMUTABLE
orCONCURRENT
, 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.OfInt
describing the stream elements -
parallel
- iftrue
then the returned stream is a parallel stream; iffalse
the returned stream is a sequential stream. - Returns:
-
a new sequential or parallel
IntStream
intStream
public static IntStream intStream(Supplier<? extends Spliterator.OfInt> supplier, int characteristics, boolean parallel)
Creates a new sequential or parallelIntStream
from aSupplier
ofSpliterator.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
IMMUTABLE
orCONCURRENT
, or that are late-binding, it is likely more efficient to useintStream(java.util.Spliterator.OfInt, boolean)
instead.The use of a
Supplier
in 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
- aSupplier
of aSpliterator.OfInt
-
characteristics
- Spliterator characteristics of the suppliedSpliterator.OfInt
. The characteristics must be equal tosupplier.get().characteristics()
, otherwise undefined behavior may occur when terminal operation commences. -
parallel
- iftrue
then the returned stream is a parallel stream; iffalse
the returned stream is a sequential stream. - Returns:
-
a new sequential or parallel
IntStream
- See Also:
-
intStream(java.util.Spliterator.OfInt, boolean)
longStream
public static LongStream longStream(Spliterator.OfLong spliterator, boolean parallel)
Creates a new sequential or parallelLongStream
from 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
IMMUTABLE
orCONCURRENT
, 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.OfLong
describing the stream elements -
parallel
- iftrue
then the returned stream is a parallel stream; iffalse
the returned stream is a sequential stream. - Returns:
-
a new sequential or parallel
LongStream
longStream
public static LongStream longStream(Supplier<? extends Spliterator.OfLong> supplier, int characteristics, boolean parallel)
Creates a new sequential or parallelLongStream
from aSupplier
ofSpliterator.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
IMMUTABLE
orCONCURRENT
, or that are late-binding, it is likely more efficient to uselongStream(java.util.Spliterator.OfLong, boolean)
instead.The use of a
Supplier
in 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
- aSupplier
of aSpliterator.OfLong
-
characteristics
- Spliterator characteristics of the suppliedSpliterator.OfLong
. The characteristics must be equal tosupplier.get().characteristics()
, otherwise undefined behavior may occur when terminal operation commences. -
parallel
- iftrue
then the returned stream is a parallel stream; iffalse
the returned stream is a sequential stream. - Returns:
-
a new sequential or parallel
LongStream
- See Also:
-
longStream(java.util.Spliterator.OfLong, boolean)
doubleStream
public static DoubleStream doubleStream(Spliterator.OfDouble spliterator, boolean parallel)
Creates a new sequential or parallelDoubleStream
from 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
IMMUTABLE
orCONCURRENT
, 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.OfDouble
describing the stream elements -
parallel
- iftrue
then the returned stream is a parallel stream; iffalse
the returned stream is a sequential stream. - Returns:
-
a new sequential or parallel
DoubleStream
doubleStream
public static DoubleStream doubleStream(Supplier<? extends Spliterator.OfDouble> supplier, int characteristics, boolean parallel)
Creates a new sequential or parallelDoubleStream
from aSupplier
ofSpliterator.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
IMMUTABLE
orCONCURRENT
, or that are late-binding, it is likely more efficient to usedoubleStream(java.util.Spliterator.OfDouble, boolean)
instead.The use of a
Supplier
in 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
- ASupplier
of aSpliterator.OfDouble
-
characteristics
- Spliterator characteristics of the suppliedSpliterator.OfDouble
. The characteristics must be equal tosupplier.get().characteristics()
, otherwise undefined behavior may occur when terminal operation commences. -
parallel
- iftrue
then the returned stream is a parallel stream; iffalse
the returned stream is a sequential stream. - Returns:
-
a new sequential or parallel
DoubleStream
- See Also:
-
doubleStream(java.util.Spliterator.OfDouble, boolean)
-
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2022, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.