Skip to content

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 elements x and y, !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 the Spliterator is capable of returning an exact count of elements (via estimateSize()).^[600-developer__java__java8__java8-Spliterator.md]
  • NONNULL (0x00000100): Guarantees that encountered elements will not be null.^[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 child Spliterators (created via trySplit()) are SIZED.^[600-developer__java__java8__java8-Spliterator.md]

Sources

  • 600-developer__java__java8__java8-Spliterator.md