The spliterator() method of PriorityBlockingQueue returns a Spliterator of the same elements as PriorityBlockingQueue. The returned iterator is weakly consistent. It can be used with Streams in Java 8. Also it can traverse elements individually and in bulk too.Spliterator is better way to traverse over element because it provides more control on elements.
public Spliterator spliterator()
Returns: This method returns a Spliterator over the elements in PriorityBlockingQueue.
Below programs illustrate spliterator() method of PriorityBlockingQueue:
Example 1: Program to demonstrate spliterator() method on PriorityBlockingQueue which contains a list of numbers.
list of Numbers: 5278367 35658786 7855642 74381793 76487590 87625142
Example 2: Program to demonstrate spliterator() method on PriorityBlockingQueue which contains a list of names.
list of Names: Joydeep Priyanka Joyita
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.