Class Spliterators
Spliterator
and its primitive specializationsSpliterator.OfInt
,Spliterator.OfLong
, andSpliterator.OfDouble
.- Since:
- 1.8
- See Also:
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
An abstractSpliterator.OfDouble
that implementstrySplit
to permit limited parallelism.static class
An abstractSpliterator.OfInt
that implementstrySplit
to permit limited parallelism.static class
An abstractSpliterator.OfLong
that implementstrySplit
to permit limited parallelism.static class
An abstractSpliterator
that implementstrySplit
to permit limited parallelism.Method Summary
Modifier and TypeMethodDescriptionstaticSpliterator.OfDouble
Creates an emptySpliterator.OfDouble
staticSpliterator.OfInt
Creates an emptySpliterator.OfInt
staticSpliterator.OfLong
Creates an emptySpliterator.OfLong
static <T> Spliterator
<T> Creates an emptySpliterator
iterator
(Spliterator.OfDouble spliterator) Creates anPrimitiveIterator.OfDouble
from aSpliterator.OfDouble
.staticPrimitiveIterator.OfInt
iterator
(Spliterator.OfInt spliterator) Creates anPrimitiveIterator.OfInt
from aSpliterator.OfInt
.staticPrimitiveIterator.OfLong
iterator
(Spliterator.OfLong spliterator) Creates anPrimitiveIterator.OfLong
from aSpliterator.OfLong
.static <T> Iterator
<T> iterator
(Spliterator<? extends T> spliterator) Creates anIterator
from aSpliterator
.staticSpliterator.OfDouble
spliterator
(double[] array, int additionalCharacteristics) Creates aSpliterator.OfDouble
covering the elements of a given array, using a customized set of spliterator characteristics.staticSpliterator.OfDouble
spliterator
(double[] array, int fromIndex, int toIndex, int additionalCharacteristics) Creates aSpliterator.OfDouble
covering a range of elements of a given array, using a customized set of spliterator characteristics.staticSpliterator.OfInt
spliterator
(int[] array, int additionalCharacteristics) Creates aSpliterator.OfInt
covering the elements of a given array, using a customized set of spliterator characteristics.staticSpliterator.OfInt
spliterator
(int[] array, int fromIndex, int toIndex, int additionalCharacteristics) Creates aSpliterator.OfInt
covering a range of elements of a given array, using a customized set of spliterator characteristics.staticSpliterator.OfLong
spliterator
(long[] array, int additionalCharacteristics) Creates aSpliterator.OfLong
covering the elements of a given array, using a customized set of spliterator characteristics.staticSpliterator.OfLong
spliterator
(long[] array, int fromIndex, int toIndex, int additionalCharacteristics) Creates aSpliterator.OfLong
covering a range of elements of a given array, using a customized set of spliterator characteristics.static <T> Spliterator
<T> spliterator
(Object[] array, int additionalCharacteristics) Creates aSpliterator
covering the elements of a given array, using a customized set of spliterator characteristics.static <T> Spliterator
<T> spliterator
(Object[] array, int fromIndex, int toIndex, int additionalCharacteristics) Creates aSpliterator
covering a range of elements of a given array, using a customized set of spliterator characteristics.static <T> Spliterator
<T> spliterator
(Collection<? extends T> c, int characteristics) static <T> Spliterator
<T> spliterator
(Iterator<? extends T> iterator, long size, int characteristics) Creates aSpliterator
using a givenIterator
as the source of elements, and with a given initially reported size.staticSpliterator.OfDouble
spliterator
(PrimitiveIterator.OfDouble iterator, long size, int characteristics) Creates aSpliterator.OfDouble
using a givenDoubleStream.DoubleIterator
as the source of elements, and with a given initially reported size.staticSpliterator.OfInt
spliterator
(PrimitiveIterator.OfInt iterator, long size, int characteristics) Creates aSpliterator.OfInt
using a givenIntStream.IntIterator
as the source of elements, and with a given initially reported size.staticSpliterator.OfLong
spliterator
(PrimitiveIterator.OfLong iterator, long size, int characteristics) Creates aSpliterator.OfLong
using a givenLongStream.LongIterator
as the source of elements, and with a given initially reported size.static <T> Spliterator
<T> spliteratorUnknownSize
(Iterator<? extends T> iterator, int characteristics) Creates aSpliterator
using a givenIterator
as the source of elements, with no initial size estimate.staticSpliterator.OfDouble
spliteratorUnknownSize
(PrimitiveIterator.OfDouble iterator, int characteristics) Creates aSpliterator.OfDouble
using a givenDoubleStream.DoubleIterator
as the source of elements, with no initial size estimate.staticSpliterator.OfInt
spliteratorUnknownSize
(PrimitiveIterator.OfInt iterator, int characteristics) Creates aSpliterator.OfInt
using a givenIntStream.IntIterator
as the source of elements, with no initial size estimate.staticSpliterator.OfLong
spliteratorUnknownSize
(PrimitiveIterator.OfLong iterator, int characteristics) Creates aSpliterator.OfLong
using a givenLongStream.LongIterator
as the source of elements, with no initial size estimate.
Method Details
emptySpliterator
Creates an emptySpliterator
The empty spliterator reports
Spliterator.SIZED
andSpliterator.SUBSIZED
. Calls toSpliterator.trySplit()
always returnnull
.- Type Parameters:
T
- Type of elements- Returns:
- An empty spliterator
emptyIntSpliterator
Creates an emptySpliterator.OfInt
The empty spliterator reports
Spliterator.SIZED
andSpliterator.SUBSIZED
. Calls toSpliterator.trySplit()
always returnnull
.- Returns:
- An empty spliterator
emptyLongSpliterator
Creates an emptySpliterator.OfLong
The empty spliterator reports
Spliterator.SIZED
andSpliterator.SUBSIZED
. Calls toSpliterator.trySplit()
always returnnull
.- Returns:
- An empty spliterator
emptyDoubleSpliterator
Creates an emptySpliterator.OfDouble
The empty spliterator reports
Spliterator.SIZED
andSpliterator.SUBSIZED
. Calls toSpliterator.trySplit()
always returnnull
.- Returns:
- An empty spliterator
spliterator
Creates aSpliterator
covering the elements of a given array, using a customized set of spliterator characteristics.This method is provided as an implementation convenience for Spliterators which store portions of their elements in arrays, and need fine control over Spliterator characteristics. Most other situations in which a Spliterator for an array is needed should use
Arrays.spliterator(Object[])
.The returned spliterator always reports the characteristics
SIZED
andSUBSIZED
. The caller may provide additional characteristics for the spliterator to report; it is common to additionally specifyIMMUTABLE
andORDERED
.- Type Parameters:
T
- Type of elements- Parameters:
array
- The array, assumed to be unmodified during useadditionalCharacteristics
- Additional spliterator characteristics of this spliterator's source or elements beyondSIZED
andSUBSIZED
which are always reported- Returns:
- A spliterator for an array
- Throws:
NullPointerException
- if the given array isnull
- See Also:
spliterator
public static <T> Spliterator<T> spliterator(Object[] array, int fromIndex, int toIndex, int additionalCharacteristics) Creates aSpliterator
covering a range of elements of a given array, using a customized set of spliterator characteristics.This method is provided as an implementation convenience for Spliterators which store portions of their elements in arrays, and need fine control over Spliterator characteristics. Most other situations in which a Spliterator for an array is needed should use
Arrays.spliterator(Object[])
.The returned spliterator always reports the characteristics
SIZED
andSUBSIZED
. The caller may provide additional characteristics for the spliterator to report; it is common to additionally specifyIMMUTABLE
andORDERED
.- Type Parameters:
T
- Type of elements- Parameters:
array
- The array, assumed to be unmodified during usefromIndex
- The least index (inclusive) to covertoIndex
- One past the greatest index to coveradditionalCharacteristics
- Additional spliterator characteristics of this spliterator's source or elements beyondSIZED
andSUBSIZED
which are always reported- Returns:
- A spliterator for an array
- Throws:
NullPointerException
- if the given array isnull
ArrayIndexOutOfBoundsException
- iffromIndex
is negative,toIndex
is less thanfromIndex
, ortoIndex
is greater than the array size- See Also:
spliterator
Creates aSpliterator.OfInt
covering the elements of a given array, using a customized set of spliterator characteristics.This method is provided as an implementation convenience for Spliterators which store portions of their elements in arrays, and need fine control over Spliterator characteristics. Most other situations in which a Spliterator for an array is needed should use
Arrays.spliterator(int[])
.The returned spliterator always reports the characteristics
SIZED
andSUBSIZED
. The caller may provide additional characteristics for the spliterator to report; it is common to additionally specifyIMMUTABLE
andORDERED
.- Parameters:
array
- The array, assumed to be unmodified during useadditionalCharacteristics
- Additional spliterator characteristics of this spliterator's source or elements beyondSIZED
andSUBSIZED
which are always reported- Returns:
- A spliterator for an array
- Throws:
NullPointerException
- if the given array isnull
- See Also:
spliterator
public static Spliterator.OfInt spliterator(int[] array, int fromIndex, int toIndex, int additionalCharacteristics) Creates aSpliterator.OfInt
covering a range of elements of a given array, using a customized set of spliterator characteristics.This method is provided as an implementation convenience for Spliterators which store portions of their elements in arrays, and need fine control over Spliterator characteristics. Most other situations in which a Spliterator for an array is needed should use
Arrays.spliterator(int[], int, int)
.The returned spliterator always reports the characteristics
SIZED
andSUBSIZED
. The caller may provide additional characteristics for the spliterator to report; it is common to additionally specifyIMMUTABLE
andORDERED
.- Parameters:
array
- The array, assumed to be unmodified during usefromIndex
- The least index (inclusive) to covertoIndex
- One past the greatest index to coveradditionalCharacteristics
- Additional spliterator characteristics of this spliterator's source or elements beyondSIZED
andSUBSIZED
which are always reported- Returns:
- A spliterator for an array
- Throws:
NullPointerException
- if the given array isnull
ArrayIndexOutOfBoundsException
- iffromIndex
is negative,toIndex
is less thanfromIndex
, ortoIndex
is greater than the array size- See Also:
spliterator
Creates aSpliterator.OfLong
covering the elements of a given array, using a customized set of spliterator characteristics.This method is provided as an implementation convenience for Spliterators which store portions of their elements in arrays, and need fine control over Spliterator characteristics. Most other situations in which a Spliterator for an array is needed should use
Arrays.spliterator(long[])
.The returned spliterator always reports the characteristics
SIZED
andSUBSIZED
. The caller may provide additional characteristics for the spliterator to report; it is common to additionally specifyIMMUTABLE
andORDERED
.- Parameters:
array
- The array, assumed to be unmodified during useadditionalCharacteristics
- Additional spliterator characteristics of this spliterator's source or elements beyondSIZED
andSUBSIZED
which are always reported- Returns:
- A spliterator for an array
- Throws:
NullPointerException
- if the given array isnull
- See Also:
spliterator
public static Spliterator.OfLong spliterator(long[] array, int fromIndex, int toIndex, int additionalCharacteristics) Creates aSpliterator.OfLong
covering a range of elements of a given array, using a customized set of spliterator characteristics.This method is provided as an implementation convenience for Spliterators which store portions of their elements in arrays, and need fine control over Spliterator characteristics. Most other situations in which a Spliterator for an array is needed should use
Arrays.spliterator(long[], int, int)
.The returned spliterator always reports the characteristics
SIZED
andSUBSIZED
. The caller may provide additional characteristics for the spliterator to report. (For example, if it is known the array will not be further modified, specifyIMMUTABLE
; if the array data is considered to have an encounter order, specifyORDERED
). The methodArrays.spliterator(long[], int, int)
can often be used instead, which returns a spliterator that reportsSIZED
,SUBSIZED
,IMMUTABLE
, andORDERED
.- Parameters:
array
- The array, assumed to be unmodified during usefromIndex
- The least index (inclusive) to covertoIndex
- One past the greatest index to coveradditionalCharacteristics
- Additional spliterator characteristics of this spliterator's source or elements beyondSIZED
andSUBSIZED
which are always reported- Returns:
- A spliterator for an array
- Throws:
NullPointerException
- if the given array isnull
ArrayIndexOutOfBoundsException
- iffromIndex
is negative,toIndex
is less thanfromIndex
, ortoIndex
is greater than the array size- See Also:
spliterator
Creates aSpliterator.OfDouble
covering the elements of a given array, using a customized set of spliterator characteristics.This method is provided as an implementation convenience for Spliterators which store portions of their elements in arrays, and need fine control over Spliterator characteristics. Most other situations in which a Spliterator for an array is needed should use
Arrays.spliterator(double[])
.The returned spliterator always reports the characteristics
SIZED
andSUBSIZED
. The caller may provide additional characteristics for the spliterator to report; it is common to additionally specifyIMMUTABLE
andORDERED
.- Parameters:
array
- The array, assumed to be unmodified during useadditionalCharacteristics
- Additional spliterator characteristics of this spliterator's source or elements beyondSIZED
andSUBSIZED
which are always reported- Returns:
- A spliterator for an array
- Throws:
NullPointerException
- if the given array isnull
- See Also:
spliterator
public static Spliterator.OfDouble spliterator(double[] array, int fromIndex, int toIndex, int additionalCharacteristics) Creates aSpliterator.OfDouble
covering a range of elements of a given array, using a customized set of spliterator characteristics.This method is provided as an implementation convenience for Spliterators which store portions of their elements in arrays, and need fine control over Spliterator characteristics. Most other situations in which a Spliterator for an array is needed should use
Arrays.spliterator(double[], int, int)
.The returned spliterator always reports the characteristics
SIZED
andSUBSIZED
. The caller may provide additional characteristics for the spliterator to report. (For example, if it is known the array will not be further modified, specifyIMMUTABLE
; if the array data is considered to have an encounter order, specifyORDERED
). The methodArrays.spliterator(long[], int, int)
can often be used instead, which returns a spliterator that reportsSIZED
,SUBSIZED
,IMMUTABLE
, andORDERED
.- Parameters:
array
- The array, assumed to be unmodified during usefromIndex
- The least index (inclusive) to covertoIndex
- One past the greatest index to coveradditionalCharacteristics
- Additional spliterator characteristics of this spliterator's source or elements beyondSIZED
andSUBSIZED
which are always reported- Returns:
- A spliterator for an array
- Throws:
NullPointerException
- if the given array isnull
ArrayIndexOutOfBoundsException
- iffromIndex
is negative,toIndex
is less thanfromIndex
, ortoIndex
is greater than the array size- See Also:
spliterator
Creates aSpliterator
using the given collection'siterator
as the source of elements, and reporting itssize
as its initial size.The spliterator islate-binding, inherits thefail-fast properties of the collection's iterator, and implements
trySplit
to permit limited parallelism.- Type Parameters:
T
- Type of elements- Parameters:
c
- The collectioncharacteristics
- Characteristics of this spliterator's source or elements. The characteristicsSIZED
andSUBSIZED
are additionally reported unlessCONCURRENT
is supplied.- Returns:
- A spliterator from an iterator
- Throws:
NullPointerException
- if the given collection isnull
spliterator
public static <T> Spliterator<T> spliterator(Iterator<? extends T> iterator, long size, int characteristics) Creates aSpliterator
using a givenIterator
as the source of elements, and with a given initially reported size.The spliterator is notlate-binding, inherits thefail-fast properties of the iterator, and implements
trySplit
to permit limited parallelism.Traversal of elements should be accomplished through the spliterator. The behaviour of splitting and traversal is undefined if the iterator is operated on after the spliterator is returned, or the initially reported size is not equal to the actual number of elements in the source.
- Type Parameters:
T
- Type of elements- Parameters:
iterator
- The iterator for the sourcesize
- The number of elements in the source, to be reported as initialestimateSize
characteristics
- Characteristics of this spliterator's source or elements. The characteristicsSIZED
andSUBSIZED
are additionally reported unlessCONCURRENT
is supplied.- Returns:
- A spliterator from an iterator
- Throws:
NullPointerException
- if the given iterator isnull
spliteratorUnknownSize
public static <T> Spliterator<T> spliteratorUnknownSize(Iterator<? extends T> iterator, int characteristics) Creates aSpliterator
using a givenIterator
as the source of elements, with no initial size estimate.The spliterator is notlate-binding, inherits thefail-fast properties of the iterator, and implements
trySplit
to permit limited parallelism.Traversal of elements should be accomplished through the spliterator. The behaviour of splitting and traversal is undefined if the iterator is operated on after the spliterator is returned.
- Type Parameters:
T
- Type of elements- Parameters:
iterator
- The iterator for the sourcecharacteristics
- Characteristics of this spliterator's source or elements (SIZED
andSUBSIZED
, if supplied, are ignored and are not reported.)- Returns:
- A spliterator from an iterator
- Throws:
NullPointerException
- if the given iterator isnull
spliterator
public static Spliterator.OfInt spliterator(PrimitiveIterator.OfInt iterator, long size, int characteristics) Creates aSpliterator.OfInt
using a givenIntStream.IntIterator
as the source of elements, and with a given initially reported size.The spliterator is notlate-binding, inherits thefail-fast properties of the iterator, and implements
trySplit
to permit limited parallelism.Traversal of elements should be accomplished through the spliterator. The behaviour of splitting and traversal is undefined if the iterator is operated on after the spliterator is returned, or the initially reported size is not equal to the actual number of elements in the source.
- Parameters:
iterator
- The iterator for the sourcesize
- The number of elements in the source, to be reported as initialestimateSize
.characteristics
- Characteristics of this spliterator's source or elements. The characteristicsSIZED
andSUBSIZED
are additionally reported unlessCONCURRENT
is supplied.- Returns:
- A spliterator from an iterator
- Throws:
NullPointerException
- if the given iterator isnull
spliteratorUnknownSize
public static Spliterator.OfInt spliteratorUnknownSize(PrimitiveIterator.OfInt iterator, int characteristics) Creates aSpliterator.OfInt
using a givenIntStream.IntIterator
as the source of elements, with no initial size estimate.The spliterator is notlate-binding, inherits thefail-fast properties of the iterator, and implements
trySplit
to permit limited parallelism.Traversal of elements should be accomplished through the spliterator. The behaviour of splitting and traversal is undefined if the iterator is operated on after the spliterator is returned.
- Parameters:
iterator
- The iterator for the sourcecharacteristics
- Characteristics of this spliterator's source or elements (SIZED
andSUBSIZED
, if supplied, are ignored and are not reported.)- Returns:
- A spliterator from an iterator
- Throws:
NullPointerException
- if the given iterator isnull
spliterator
public static Spliterator.OfLong spliterator(PrimitiveIterator.OfLong iterator, long size, int characteristics) Creates aSpliterator.OfLong
using a givenLongStream.LongIterator
as the source of elements, and with a given initially reported size.The spliterator is notlate-binding, inherits thefail-fast properties of the iterator, and implements
trySplit
to permit limited parallelism.Traversal of elements should be accomplished through the spliterator. The behaviour of splitting and traversal is undefined if the iterator is operated on after the spliterator is returned, or the initially reported size is not equal to the actual number of elements in the source.
- Parameters:
iterator
- The iterator for the sourcesize
- The number of elements in the source, to be reported as initialestimateSize
.characteristics
- Characteristics of this spliterator's source or elements. The characteristicsSIZED
andSUBSIZED
are additionally reported unlessCONCURRENT
is supplied.- Returns:
- A spliterator from an iterator
- Throws:
NullPointerException
- if the given iterator isnull
spliteratorUnknownSize
public static Spliterator.OfLong spliteratorUnknownSize(PrimitiveIterator.OfLong iterator, int characteristics) Creates aSpliterator.OfLong
using a givenLongStream.LongIterator
as the source of elements, with no initial size estimate.The spliterator is notlate-binding, inherits thefail-fast properties of the iterator, and implements
trySplit
to permit limited parallelism.Traversal of elements should be accomplished through the spliterator. The behaviour of splitting and traversal is undefined if the iterator is operated on after the spliterator is returned.
- Parameters:
iterator
- The iterator for the sourcecharacteristics
- Characteristics of this spliterator's source or elements (SIZED
andSUBSIZED
, if supplied, are ignored and are not reported.)- Returns:
- A spliterator from an iterator
- Throws:
NullPointerException
- if the given iterator isnull
spliterator
public static Spliterator.OfDouble spliterator(PrimitiveIterator.OfDouble iterator, long size, int characteristics) Creates aSpliterator.OfDouble
using a givenDoubleStream.DoubleIterator
as the source of elements, and with a given initially reported size.The spliterator is notlate-binding, inherits thefail-fast properties of the iterator, and implements
trySplit
to permit limited parallelism.Traversal of elements should be accomplished through the spliterator. The behaviour of splitting and traversal is undefined if the iterator is operated on after the spliterator is returned, or the initially reported size is not equal to the actual number of elements in the source.
- Parameters:
iterator
- The iterator for the sourcesize
- The number of elements in the source, to be reported as initialestimateSize
characteristics
- Characteristics of this spliterator's source or elements. The characteristicsSIZED
andSUBSIZED
are additionally reported unlessCONCURRENT
is supplied.- Returns:
- A spliterator from an iterator
- Throws:
NullPointerException
- if the given iterator isnull
spliteratorUnknownSize
public static Spliterator.OfDouble spliteratorUnknownSize(PrimitiveIterator.OfDouble iterator, int characteristics) Creates aSpliterator.OfDouble
using a givenDoubleStream.DoubleIterator
as the source of elements, with no initial size estimate.The spliterator is notlate-binding, inherits thefail-fast properties of the iterator, and implements
trySplit
to permit limited parallelism.Traversal of elements should be accomplished through the spliterator. The behaviour of splitting and traversal is undefined if the iterator is operated on after the spliterator is returned.
- Parameters:
iterator
- The iterator for the sourcecharacteristics
- Characteristics of this spliterator's source or elements (SIZED
andSUBSIZED
, if supplied, are ignored and are not reported.)- Returns:
- A spliterator from an iterator
- Throws:
NullPointerException
- if the given iterator isnull
iterator
Creates anIterator
from aSpliterator
.Traversal of elements should be accomplished through the iterator. The behaviour of traversal is undefined if the spliterator is operated after the iterator is returned.
- Type Parameters:
T
- Type of elements- Parameters:
spliterator
- The spliterator- Returns:
- An iterator
- Throws:
NullPointerException
- if the given spliterator isnull
iterator
Creates anPrimitiveIterator.OfInt
from aSpliterator.OfInt
.Traversal of elements should be accomplished through the iterator. The behaviour of traversal is undefined if the spliterator is operated after the iterator is returned.
- Parameters:
spliterator
- The spliterator- Returns:
- An iterator
- Throws:
NullPointerException
- if the given spliterator isnull
iterator
Creates anPrimitiveIterator.OfLong
from aSpliterator.OfLong
.Traversal of elements should be accomplished through the iterator. The behaviour of traversal is undefined if the spliterator is operated after the iterator is returned.
- Parameters:
spliterator
- The spliterator- Returns:
- An iterator
- Throws:
NullPointerException
- if the given spliterator isnull
iterator
Creates anPrimitiveIterator.OfDouble
from aSpliterator.OfDouble
.Traversal of elements should be accomplished through the iterator. The behaviour of traversal is undefined if the spliterator is operated after the iterator is returned.
- Parameters:
spliterator
- The spliterator- Returns:
- An iterator
- Throws:
NullPointerException
- if the given spliterator isnull