ArchitectMind
  1. Home
  2. Java Ecosystem
  3. Book 1 · Core Java & Modern Java
  4. Volume II
  5. Spliterator
Book 1 · Volume II — Generics, Collections & Type System · Topic 6.3

Spliterator

Splitting, parallel traversal, ordering and characteristics

12 min readStage 1 · Foundations14 interview questions
Prerequisites
6.1 Iterator
Covers
Splitting · Parallel traversal · Ordering · Characteristics
Related
B1V3 Streams and parallel streams · B2V4 ForkJoinPool
On this page
  1. 1. Concept / Definition
  2. 2. Why It Exists
  3. 3. Core Concepts
  4. 4. How It Works Internally
  5. 5. APIs / Features / Syntax
  6. 6. Practical Examples
  7. 7. Common Problems & Mistakes
  8. 8. Performance & Production Considerations
  9. 9. Architecture & Design Considerations
  10. 10. Interview Questions & Answers
  11. Key Takeaways

1Concept / Definition

A Spliterator ("splittable iterator", Java 8) traverses elements like an iterator but can also split itself into two parts so that different threads can process them in parallel. It also reports characteristics — facts about the source such as ordering, exact size and distinctness — that the Streams framework uses to optimise pipelines. Every Collection provides one through spliterator(), and every stream is built on one.

2Why It Exists

Java 8 added streams and, with them, the promise that parallelStream() could spread work across cores. Iterator cannot support that. Its protocol is strictly sequential: one caller asks hasNext(), then next(), one element at a time, and nothing in the interface lets a second thread take a share of the remaining elements. It also says nothing about the source, so a framework cannot know the size, the order or whether duplicates are possible.

Spliterator was designed to fill both gaps. trySplit() hands part of the work to another thread; tryAdvance() merges hasNext() and next() into one call, which is cheaper and removes the race between the two; estimateSize() and characteristics() describe the source, so the stream framework can size its buffers, skip work that the source already guarantees and decide how far to split. Every collection and every stream source provides one.

3Core Concepts

Splitting

trySplit() hands off a portion of the remaining elements as a new Spliterator and keeps the rest, or returns null if it cannot or should not split further. Array-backed sources (ArrayList, arrays, IntStream.range) split cheaply and evenly by halving an index range; linked or hash-based sources split less evenly; iterator-backed sources split poorly, copying batches into arrays. Split quality largely determines how well a parallel stream scales.

Recursive splitting of an array-backed source
Figure 1 — Recursive splitting of an array-backed source

Parallel traversal

A parallel stream splits the source spliterator recursively until pieces are small enough, submits them as tasks to the common ForkJoinPool, traverses each with tryAdvance or forEachRemaining, and combines partial results. Traversal itself is sequential within each piece; parallelism comes only from splitting.

The steps of a parallel stream execution
Figure 2 — The steps of a parallel stream execution

Ordering

If a spliterator is ORDERED, splits must preserve encounter order: the prefix goes to one part and the suffix to the other, and combining must respect order. Operations such as findFirst, limit and forEachOrdered then do extra coordination in parallel. Calling unordered() on a stream, or using findAny and forEach, releases this constraint and can make parallel pipelines much faster.

Characteristics

characteristics() returns bit flags that the framework trusts: SIZED allows pre-sized result arrays and skipping of count work; DISTINCT lets distinct() become a no-op; SORTED lets sorted() be skipped when the source is in natural order; IMMUTABLE and CONCURRENT describe how the source tolerates modification; NONNULL rules out nulls. Reporting a characteristic that is not true leads to wrong results.

The characteristic flags
Figure 3 — The characteristic flags

4How It Works Internally

ArrayList's spliterator is three numbers over the list's own array: index, the next element to visit; fence, one past the last element it covers; and expectedModCount. It is late-binding: fence and expectedModCount are read from the list only when the spliterator is first used, so changes made between spliterator() and the start of traversal are seen. trySplit() computes mid = (index + fence) >>> 1, returns a new spliterator for the prefix [index, mid) and keeps [mid, fence) itself, in constant time and with exact sizes on both sides (Figure 4). forEachRemaining walks its range in a tight loop and checks modCount once at the end.

ArrayList splits by halving an index range; the stream framework decides how far to split
Figure 4 — ArrayList splits by halving an index range; the stream framework decides how far to split

The stream framework decides how far to split. For a parallel pipeline it computes a target leaf size of about estimateSize() / (parallelism x 4), where parallelism is the common pool's, normally the number of cores minus one. A task splits its spliterator while it is larger than the target and trySplit() does not return null, forks the prefix as a new task and continues with the rest; leaves are traversed sequentially and their results combined as the tasks complete. Sources that cannot split by index fall back to batching: LinkedList, spliteratorUnknownSize and other iterator-based spliterators copy the next batch of elements (1,024 at first, growing on each split) into an array and hand that off, which is why small linked sources do not split at all (Example 2).

5APIs / Features / Syntax

The methods a spliterator implements, and the helpers that build one for a custom source:

Method or helperPurposeNotes
boolean tryAdvance(Consumer)Process the next element, if anyReplaces hasNext() + next()
void forEachRemaining(Consumer)Process all remaining elementsDefault loops over tryAdvance; override for speed
Spliterator<T> trySplit()Hand off a prefix, keep the restnull = cannot or should not split
long estimateSize() / getExactSizeIfKnown()Remaining elementsExact only with SIZED; else -1 from getExactSizeIfKnown
int characteristics() / hasCharacteristics(f)Flags describing the sourceORDERED, DISTINCT, SORTED, SIZED, NONNULL, IMMUTABLE, CONCURRENT, SUBSIZED
Comparator getComparator()The order of a SORTED sourcenull = natural order; throws if not SORTED
Spliterators.spliterator(array, flags)Spliterator over an array or rangeSplits evenly, SIZED
Spliterators.spliteratorUnknownSize(it, flags)Wrap an IteratorSplits in batches
StreamSupport.stream(spliterator, parallel)Build a Stream on a spliteratorAlso intStream, longStream, doubleStream

Spliterator.OfInt, OfLong and OfDouble are primitive versions that avoid boxing; IntStream.range and Arrays.stream(int[]) use them. To write a custom spliterator, extend Spliterators.AbstractSpliterator when only tryAdvance is practical (it then splits in batches), or implement Spliterator directly when the source can split by position (Example 3).

6Practical Examples

Example 1 — Inspecting and using spliterators

Problem. Before tuning a parallel pipeline, check what the source reports and how it splits, and see which terminal operations add ordering work. array stands for any String[] that the code wants to stream.

JAVAInspecting and using spliterators
List<Integer> numbers = IntStream.range(0, 1_000).boxed().toList();
Spliterator<Integer> all = numbers.spliterator();
System.out.println(all.hasCharacteristics(Spliterator.SIZED | Spliterator.ORDERED)); // true

// [0, 500) — "all" keeps [500, 1000)
Spliterator<Integer> firstHalf = all.trySplit();
// 500 500
System.out.println(firstHalf.estimateSize() + " " + all.estimateSize());

// Ordering constraints in parallel
long count = numbers.parallelStream().filter(n -> n % 7 == 0).count();  // cheap
// unordered: fast
Optional<Integer> any = numbers.parallelStream().filter(n -> n > 900).findAny();
Optional<Integer> first = numbers.parallelStream().filter(n -> n > 900).findFirst(); // ordered: extra work

// Custom source with a good spliterator: wrap an array
Spliterator<String> fromArray = Spliterators.spliterator(array, Spliterator.ORDERED | Spliterator.IMMUTABLE);
Stream<String> stream = StreamSupport.stream(fromArray, true);

Why it works. A list from toList() is array-backed and reports SIZED and ORDERED, so one trySplit() gives two exact halves of 500. count() needs no ordering at all; findAny() may return whichever match a worker finds first, while findFirst() must return 901 and so has to wait for, or cancel, the work on earlier ranges. Spliterators.spliterator(array, ...) adds SIZED and SUBSIZED to the given flags, so the custom stream splits as well as an ArrayList does.

Example 2 — Mini program: watching sources split

Problem. Section 3 says that split quality determines how well a parallel stream scales. This program performs the splits itself, the way the stream framework would, and prints the result for an ArrayList, a LinkedList and a HashSet, followed by the characteristics each source reports.

JAVASplitTree.java
public class SplitTree {
    static void split(Spliterator<Integer> s, int depth, StringBuilder out) {
        String pad = "  ".repeat(depth);
        long size = s.estimateSize();
        Spliterator<Integer> prefix = size > 4 ? s.trySplit() : null;
        if (prefix == null) {                          // a leaf: traverse it
            List<Integer> leaf = new ArrayList<>();
            s.forEachRemaining(leaf::add);
            out.append(pad + "leaf " + leaf + "\n");
            return;
        }
        out.append(pad + size + " -> " + prefix.estimateSize() + " + "
                + s.estimateSize() + "\n");
        split(prefix, depth + 1, out);            // prefix first: order kept
        split(s, depth + 1, out);
    }
 
    static String counts(Collection<Integer> c) {   // sizes after one split
        Spliterator<Integer> rest = c.spliterator(), first = rest.trySplit();
        long[] n = new long[2];
        if (first != null) first.forEachRemaining(x -> n[0]++);
        rest.forEachRemaining(x -> n[1]++);
        return n[0] + " + " + n[1];
    }
 
    static String flags(Spliterator<?> s) {
        String[] names = {"ORDERED", "DISTINCT", "SORTED", "SIZED", "IMMUT."};
        int[] bits = {Spliterator.ORDERED, Spliterator.DISTINCT,
                Spliterator.SORTED, Spliterator.SIZED, Spliterator.IMMUTABLE};
        StringJoiner j = new StringJoiner(" ");
        for (int i = 0; i < bits.length; i++)
            if (s.hasCharacteristics(bits[i])) j.add(names[i]);
        return j.toString();
    }
 
    public static void main(String[] args) {
        List<Integer> nums = IntStream.range(0, 16).boxed().toList();
        StringBuilder tree = new StringBuilder();
        split(new ArrayList<>(nums).spliterator(), 0, tree);
        System.out.print("ArrayList, 16 elements, split to <= 4:\n" + tree);
        String linked = counts(new LinkedList<>(nums));
        String hashed = counts(new HashSet<>(nums));
        System.out.println("first split: LinkedList " + linked
                + ", HashSet " + hashed);
        Map<String, Collection<Integer>> sources = new LinkedHashMap<>();
        sources.put("ArrayList", new ArrayList<>(nums));
        sources.put("HashSet", new HashSet<>(nums));
        sources.put("TreeSet", new TreeSet<>(nums));
        sources.put("List.of", List.of(1, 2, 3));
        sources.forEach((name, c) ->
                System.out.printf("%-10s %s%n", name, flags(c.spliterator())));
    }
}
OUTPUT
ArrayList, 16 elements, split to <= 4:
16 -> 8 + 8
  8 -> 4 + 4
    leaf [0, 1, 2, 3]
    leaf [4, 5, 6, 7]
  8 -> 4 + 4
    leaf [8, 9, 10, 11]
    leaf [12, 13, 14, 15]
first split: LinkedList 16 + 0, HashSet 16 + 0
ArrayList  ORDERED SIZED
HashSet    DISTINCT SIZED
TreeSet    ORDERED DISTINCT SORTED SIZED
List.of    ORDERED SIZED

Why it behaves this way. The ArrayList halves exactly at every level, and because the prefix is processed first the leaves come out in encounter order. The LinkedList cannot jump to its middle: its first split copies a batch of up to 1,024 elements into an array, which here takes all 16 and leaves nothing, so the whole list would run on one thread. The HashSet splits its bucket table in half, and the small integers 0 to 15 all hash into the first half, so it is just as unbalanced. The flags explain section 3's optimisations: only the TreeSet reports SORTED and DISTINCT, and the HashSet does not report ORDERED, so parallel operations on it need no order coordination.

Example 3 — A custom spliterator over fixed-width records

Problem. An import job reads a large buffer of fixed-width records, 11 characters each: a 5-digit id and a 6-digit amount. Wrapping an iterator would split in batches; a spliterator that knows the record width can split exactly in half, on record boundaries, in constant time.

JAVARecordSpliterator.java
public class RecordSpliterator implements Spliterator<String> {
    static final int WIDTH = 11;                 // 5-digit id + 6-digit amount
    private final CharSequence buf;
    private int pos;                             // first record, inclusive
    private final int end;                       // last record, exclusive
 
    RecordSpliterator(CharSequence buf, int pos, int end) {
        this.buf = buf; this.pos = pos; this.end = end;
    }
    @Override public boolean tryAdvance(Consumer<? super String> action) {
        if (pos >= end) return false;
        int from = pos++ * WIDTH;
        action.accept(buf.subSequence(from, from + WIDTH).toString());
        return true;
    }
    @Override public Spliterator<String> trySplit() {
        int mid = (pos + end) >>> 1;             // whole records only
        if (mid <= pos) return null;
        Spliterator<String> prefix = new RecordSpliterator(buf, pos, mid);
        pos = mid;                               // this one keeps the suffix
        return prefix;
    }
    @Override public long estimateSize() { return end - pos; }
    @Override public int characteristics() {
        return ORDERED | SIZED | SUBSIZED | IMMUTABLE | NONNULL;
    }
 
    static long total(CharSequence buf, int n, boolean parallel) {
        return StreamSupport.stream(new RecordSpliterator(buf, 0, n), parallel)
                .mapToLong(r -> Long.parseLong(r.substring(5))).sum();
    }
 
    public static void main(String[] args) {
        StringBuilder buf = new StringBuilder();
        for (int i = 0; i < 100_000; i++)
            buf.append(String.format("%05d%06d", i, i % 997));
        int n = buf.length() / WIDTH;
        Spliterator<String> rest = new RecordSpliterator(buf, 0, n);
        Spliterator<String> first = rest.trySplit();
        first.tryAdvance(r -> System.out.println("prefix starts with " + r));
        rest.tryAdvance(r -> System.out.println("suffix starts with " + r));
        System.out.println(n + " records, sequential total "
                + total(buf, n, false) + ", parallel " + total(buf, n, true));
    }
}
OUTPUT
prefix starts with 00000000000
suffix starts with 50000000150
100000 records, sequential total 49695450, parallel 49695450

Why it behaves this way. The spliterator works in record indexes, so mid is always a whole record and no record is cut in two; the prefix ends at record 49,999 and the suffix starts with record 50,000. Because the buffer is not changed and each piece reports its exact size, it can honestly declare SIZED, SUBSIZED and IMMUTABLE. The parallel total matches the sequential one, which is the first test any custom spliterator needs, as Q6 recommends.

Example 4 — False characteristics give wrong answers

Problem. A team wraps an external data feed in AbstractSpliterator and, to "help the stream optimiser", declares it DISTINCT and SORTED. This program shows what the framework does with flags that are not true.

JAVALyingFlags.java
public class LyingFlags {
    static Spliterator<Integer> source(List<Integer> data, long n, int flags) {
        Iterator<Integer> it = data.iterator();
        return new Spliterators.AbstractSpliterator<>(n, flags) {
            public boolean tryAdvance(Consumer<? super Integer> action) {
                if (!it.hasNext()) return false;
                action.accept(it.next());
                return true;
            }
            @Override public Comparator<? super Integer> getComparator() {
                return null;                     // SORTED means natural order
            }
        };
    }
 
    static List<Integer> distinctSorted(Spliterator<Integer> s) {
        return StreamSupport.stream(s, false).distinct().sorted().toList();
    }
 
    public static void main(String[] args) {
        List<Integer> data = List.of(3, 1, 3, 2);
        int ok = Spliterator.ORDERED | Spliterator.SIZED;
        int lying = ok | Spliterator.DISTINCT | Spliterator.SORTED;
        System.out.println("honest: " + distinctSorted(source(data, 4, ok)));
        System.out.println("lying:  " + distinctSorted(source(data, 4, lying)));
        Spliterator<Integer> empty = source(List.of(), 10, Spliterator.SIZED);
        System.out.println("empty source claiming SIZED 10, count(): "
                + StreamSupport.stream(empty, false).count());
    }
}
OUTPUT
honest: [1, 2, 3]
lying:  [3, 1, 3, 2]
empty source claiming SIZED 10, count(): 10

Why it behaves this way. Characteristics are promises, and the framework does not check them. With DISTINCT declared, distinct() is removed from the pipeline; with SORTED and a null comparator, so does sorted(), and the duplicates and the original order come straight through. With SIZED, count() returns the declared size without traversing at all (Q8), so an empty source counts as 10. Declare only what the source guarantees in every case.

7Common Problems & Mistakes

MistakeConsequenceBetter approach
Parallel streams over LinkedList, iterators or I/O sourcesPoor or no splitting: little or negative speed-up (Example 2)Copy into an array or ArrayList first, or stay sequential
Custom spliterators reporting SIZED, DISTINCT or SORTED incorrectlydistinct(), sorted() or count() are skipped and give wrong results silently (Example 4)Report only guaranteed characteristics; test parallel against sequential
Assuming parallel = fasterFor small data or cheap per-element work, splitting and combining overhead dominatesMeasure with JMH; use parallel only for large CPU-bound work (Figure 5)
Blocking I/O inside parallel streamsTies up the common ForkJoinPool shared by the whole JVM; unrelated requests slow downUse an executor, ideally virtual threads, for I/O-bound fan-out
Side effects in parallel lambdas (adding to a shared ArrayList)Lost elements, wrong sizes or ArrayIndexOutOfBoundsExceptionUse collect(...) or toList(); keep lambdas free of shared state
findFirst, limit or forEachOrdered in parallel when order does not matterExtra coordination and buffering for an order nobody needsfindAny, forEach or unordered()

8Performance & Production Considerations

Parallel streams share the common ForkJoinPool, sized to the number of cores minus one. In server applications that already use all cores for concurrent requests, parallel streams rarely help and can hurt latency for everyone. They pay off for large, CPU-bound, easily splittable workloads (arrays, ArrayList, ranges) with cheap combining; measure with JMH before adopting.

Four questions before a parallel stream; any "no" means stay sequential
Figure 5 — Four questions before a parallel stream; any "no" means stay sequential

The first question is a rule of thumb, not a law: multiply the number of elements by the work per element. Summing a million integers is cheap per element and still gains only a little; resizing a thousand images gains a lot. If the pool may be busy with other requests, a dedicated ForkJoinPool or executor isolates the batch work, at the cost of more threads competing for the same cores.

9Architecture & Design Considerations

The Spliterator's split-then-combine model is the in-process form of data-parallel processing that frameworks such as Spark and MapReduce apply across machines: partition the source, process partitions independently, merge results. The same factors determine success at both scales — balanced partitions, independent work, and cheap, associative combining.

10Interview Questions & Answers

Q1L1 · BasicConcept

What is a Spliterator?

An iterator that can also split its remaining elements into two parts for parallel processing and that reports characteristics about its source. It underlies all streams.

Q2L2 · IntermediateConcept

What does trySplit do?

It returns a new Spliterator covering part of the remaining elements (the prefix, if ordered) and keeps the rest, or returns null when splitting is not possible or worthwhile.

Q3L2 · IntermediateInternals

Why do parallel streams over ArrayList scale better than over LinkedList?

ArrayList's spliterator splits in O(1) into exact halves by index; LinkedList must walk nodes and splits into batches, producing unbalanced, costly splits.

Q4L3 · Senior EngineerInternals

How do spliterator characteristics affect stream performance?

The stream framework uses them to skip work: SIZED enables exact-size allocation, DISTINCT makes distinct() redundant, SORTED makes sorted() redundant, and lack of ORDERED lets parallel operations avoid order-preserving coordination.

Q5L3 · Senior EngineerScenario

Why might a parallel stream make a web service slower?

It runs on the shared common ForkJoinPool, competing with other requests' parallel work and with request threads for the same cores. For small datasets or I/O-bound tasks the splitting overhead exceeds any gain, and blocking tasks can starve the pool.

Q6L4 · Technical ArchitectDesign

When would you design a custom Spliterator?

For a large custom data source — a memory-mapped file, a columnar buffer, a custom tree — that should support efficient parallel streams. It should split evenly and cheaply, report accurate characteristics and size estimates, and be validated against a sequential baseline.

Q7L1 · BasicConcept

Which two Iterator methods does tryAdvance replace, and why is one method better?

hasNext() and next(). tryAdvance(action) processes the next element if there is one and returns whether it did, so a traversal needs one call per element instead of two, and there is no window between a check and a fetch in which the source could change. Bulk traversal goes further with forEachRemaining, which a source can implement as a single tight loop.

Q8L2 · IntermediateCode

What does this program print?

JAVAPeekCount.java
public class PeekCount {
    public static void main(String[] args) {
        List<String> ids = List.of("a", "b", "c");
        long n1 = ids.stream().peek(s -> System.out.print(s + " ")).count();
        long n2 = ids.stream().filter(s -> true)
                     .peek(s -> System.out.print(s.toUpperCase() + " "))
                     .count();
        System.out.println(n1 + " " + n2);
    }
}

It prints A B C 3 3. Since Java 9, count() on a pipeline whose size is known in advance takes the size from the SIZED spliterator and does not traverse, so the first peek never runs. filter may remove elements, so the second pipeline loses SIZED, must traverse, and its peek prints A, B and C. Never rely on peek or other side effects to run in a stream.

Q9L3 · Senior EngineerCode

What does this program print?

JAVASplitQuiz.java
public class SplitQuiz {
    public static void main(String[] args) {
        List<Integer> a = new ArrayList<>();
        for (int i = 1; i <= 10; i++) a.add(i);
        Spliterator<Integer> s = a.spliterator();
        Spliterator<Integer> p = s.trySplit();
        p.tryAdvance(x -> System.out.print(x + " "));
        s.tryAdvance(x -> System.out.print(x + " "));
        System.out.println(p.estimateSize() + " " + s.estimateSize());
    }
}

It prints 1 6 4 4. trySplit() returns the prefix: for indexes 0 to 9 it computes mid 5 and hands back elements 1 to 5, while the original keeps 6 to 10. Each tryAdvance consumes one element from its own half, so both report four remaining. The split is exact because ArrayList is array-backed (Figure 4).

Q10L3 · Senior EngineerTricky

You call list.spliterator() on an ArrayList, then add an element, then traverse. Does the traversal see the new element? What if you add during traversal?

Yes. ArrayList's spliterator is late-binding: it reads the list's size and modCount only when it is first used, so changes made before traversal starts are included. A change during traversal is a different matter: forEachRemaining compares modCount at the end and throws ConcurrentModificationException, after the elements have already been processed. The kit's LateBinding program shows both cases.

Q11L3 · Senior EngineerScenario

A service enriches 200 order ids per request with orders.parallelStream().map(id -> client.fetch(id)). Under load, latency of the whole service rises, including endpoints that do no enrichment. Diagnose and fix.

The remote calls block inside the common ForkJoinPool, which has only cores-minus-one threads and is shared by every parallel stream in the JVM. Concurrent requests queue behind each other's blocked tasks, so unrelated parallel work slows down too, and the fan-out per request is limited to a handful of calls at a time. Move the I/O to an executor sized for I/O, today typically Executors.newVirtualThreadPerTaskExecutor(), submit one task per id with a timeout, or use a batch endpoint; keep parallel streams for CPU-bound work (Figure 5).

Q12L4 · Technical ArchitectTrade-off

For a CPU-heavy batch step inside a service, how do you choose between a parallel stream, an ExecutorService and staying sequential?

A parallel stream is the least code and splits data automatically, but it runs on the shared common pool, offers no per-task timeout or priority, and hides the degree of parallelism. An ExecutorService or a dedicated ForkJoinPool isolates the work, bounds its threads and allows cancellation and metrics, at the cost of more code. Sequential is right when the step is small, when the service already keeps all cores busy with requests, or when latency predictability matters more than throughput. Decide with a load test that measures both the batch and the other endpoints.

Q13L5 · Solution ArchitectDesign

A daily job must aggregate a 50 GB file of fixed-width records. When do you do it in one JVM with a custom spliterator, and when do you move to a distributed engine?

One JVM is simplest when the data fits on one machine's disk, the job finishes within its window on that machine's cores and a failure can simply be rerun: memory-map the file, split it by record index as in Example 3, and aggregate with a parallel stream or a fork/join task. Move to Spark or a similar engine when the data keeps growing beyond one machine, the window becomes too short, or partial failures must be recovered without rerunning everything. The design principles stay the same: even partitions, independent work and an associative combine (section 9).

Q14L5 · Solution ArchitectTrade-off

A platform team proposes banning parallel streams in all services. Do you agree?

A blanket ban removes a class of production incidents, blocking I/O and pool contention in the common pool, and most request-handling code gains nothing from parallel streams. But it also blocks legitimate uses in batch jobs, analytics and CPU-heavy computations where measured speed-ups are large. A better policy is "sequential by default, parallel with evidence": allow it where a benchmark or load test shows the gain, forbid blocking calls in parallel pipelines through review or static analysis, and require a dedicated pool for long-running parallel work.

Test your knowledge on this topic →Flashcards from this topic's 14 questions, filtered by level and type.

Key Takeaways

  • Spliterator = iterator + trySplit + characteristics.
  • Parallel streams split recursively and combine results on the common ForkJoinPool.
  • Ordering constrains parallel operations; unordered can be faster.
  • Array-backed sources split well; linked and I/O sources do not.
Free question pack

Get 100 free Core Java interview questions

Subscribe for the Book 1 question pack (PDF, every answer explained) and new tutorials once a week. No spam, unsubscribe anytime. What is in the pack?

Almost done! Check your inbox and click the confirmation link. Your download link arrives as soon as you confirm.