ConcurrentLinkedQueue spliterator() method in Java
The spliterator() method of ConcurrentLinkedQueue is used to get a Spliterator of the same elements as ConcurrentLinkedQueue. Created Spliterator 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 ConcurrentLinkedQueue.
Below programs illustrate spliterator() method of ConcurrentLinkedQueue:
list of Numbers: 4353, 377139, 624378, 654793, 764764, 838494, 632845,
list of Strings: Aman, Amar, Sanjeet, Rabi, Debasis, Raunak, Mahesh,
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.