Java Spliterator Example

By | June 22, 2020

In this post, We will talk and learn about Java Spliterator Using an example

Java Spliterator interface is an example of an internal iterator that breaks down the stream into the smaller parts and these smaller parts can be processed in parallel.

Features  Of Spliterator :

The following are the list of features provided by Spliterator in Java.

  1. Spliterator was introduced in Java 8
  2. It provides support for parallel processing of the stream of elements for the collection framework.
  3. It provides tryAdvance()method to iterate elements individually by different threads. It helps in parallel processing.
  4. We may use to iterate elements sequentially in a single Thread, use forEachRemaining()
  5. The method trySplit() is used partition the spliterator, if it is possible.

Output of this Program:

Traversing the first half of the spliterator..
Traversing the second half of the spliterator..


You May Also Like:

What are new Features added in Java 8?
When we choose LongAdder and LongAccumulator over AtomicLong & AtomicInteger ?
How can we maintain Immutability of a class with a mutable reference ?
What is BlockingQueue? How can we implement Producer and Consumer problem using Blocking Queue?
How to get number of available processors in Java ?

That’s all about Java Spliterator Example?
If you have any feedback or suggestion please feel free to drop in below comment box.

Leave a Reply

Your email address will not be published. Required fields are marked *