J.IV · Java 25 practice question
When the built-in operations on a Stream do not provide the custom traversal behavior a developer needs, which two BaseStream operations can be used for controlled traversal?
Check answer and explanation
Correct answer: BaseStream.iterator() and BaseStream.spliterator()
Explanation
The Java SE 25 Stream documentation specifies that BaseStream.iterator() and BaseStream.spliterator() can be used to perform a controlled traversal when standard stream operations are insufficient.
Common trap
forEach() and toArray() are terminal operations on Stream rather than BaseStream escape hatches for controlled traversal. sequential() and unordered() only configure stream execution characteristics and do not provide element-by-element traversal.
Source: Java SE 25 API: Stream
Checked against the cited text on 2026-11-25.