java.util · java.base · since Java 1.8

Spliterator

declaration
public interface Spliterator<T>

The traversal-and-partition primitive under the Stream API: advance one element, split off a chunk for parallelism, and advertise characteristics the pipeline optimizes on.

  • You rarely implement one directly — Collection.spliterator() and the Stream framework provide them.

Key methods

boolean tryAdvance(Consumer<? super T> action)Process the next element if present; false when exhausted.
Spliterator<T> trySplit()Split off a prefix chunk for parallel work (null if not splittable).
long estimateSize()Estimated remaining count — drives parallel task sizing.
int characteristics()Bit flags: ORDERED, SORTED, SIZED, DISTINCT, IMMUTABLE, NONNULL...
void forEachRemaining(Consumer<? super T> action)Bulk-process the rest sequentially.