September 2019
Intermediate to advanced
816 pages
18h 47m
English
A Java Spliterator interface (also known as a splittable iterator) is an interface that's used to traverse the elements of a source (for example, a collection or stream) in parallel. This interface defines the following methods:
public interface Spliterator<T> { boolean tryAdvance(Consumer<? super T> action); Spliterator<T> trySplit(); long estimateSize(); int characteristics();}
Let's consider a simple list of 10 integers:
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
We can obtain a Spliterator interface for this list like so:
Spliterator<Integer> s1 = numbers.spliterator();
We can also do the same from a stream:
Spliterator<Integer> s1 = numbers.stream().spliterator();
In order to advance to (traverse) ...
Read now
Unlock full access