java8
What is a Spliterator? Diff between Iterator vs Spliterator.
Spliterator (Splitable Iterator) is used for traversing and partitioning sequences.
Key Differences:
- Parallelism: Iterator is strictly sequential. Spliterator is designed to support parallel processing (used by Streams).
- Method: Iterator uses
next(). Spliterator usestryAdvance()(combination of hasNext and next). - Splitting: Spliterator has
trySplit()which partitions a portion of elements into a new Spliterator for parallel threads.