Spliterator¶
The Spliterator is a public interface introduced in Java 8, serving as a core component for traversing and partitioning sequences of elements, particularly within the Stream API. It is typically utilized alongside the Spliterators utility class and implemented by various pipeline stages, such as ReferencePipeline.^[600-developer__java__java8__java8-Spliterator.md]
Characteristics¶
The behavior and capabilities of a Spliterator are defined by a set of bit-flag values known as characteristics.^[600-developer__java__java8__java8-Spliterator.md] These flags define properties of the data source and the iterator:
- ORDERED (
0x00000010): Indicates that elements have a defined encounter order.^[600-developer__java__java8__java8-Spliterator.md] - DISTINCT (
0x00000001): Indicates that for each pair of encountered elementsxandy,!x.equals(y).^[600-developer__java__java8__java8-Spliterator.md] - SORTED (
0x00000004): Indicates that elements follow a defined sort order.^[600-developer__java__java8__java8-Spliterator.md] - SIZED (
0x00000040): Indicates that theSpliteratoris capable of returning an exact count of elements (viaestimateSize()).^[600-developer__java__java8__java8-Spliterator.md] - NONNULL (
0x00000100): Guarantees that encountered elements will not benull.^[600-developer__java__java8__java8-Spliterator.md] - IMMUTABLE (
0x00000400): Indicates that the element source cannot be structurally modified.^[600-developer__java__java8__java8-Spliterator.md] - CONCURRENT (
0x00001000): Indicates that the element source may be safely modified concurrently by other threads.^[600-developer__java__java8__java8-Spliterator.md] - SUBSIZED (
0x00004000): Indicates that all childSpliterators(created viatrySplit()) areSIZED.^[600-developer__java__java8__java8-Spliterator.md]
Related Concepts¶
- Java Stream API
- [[Internal Iteration]]
- Fork/Join Framework
Sources¶
600-developer__java__java8__java8-Spliterator.md