VOOZH about

URL: https://www.geeksforgeeks.org/java/java-8-linkedblockingqueue-spliterator-method-with-examples/

⇱ Java 8 | LinkedBlockingQueue spliterator() method with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java 8 | LinkedBlockingQueue spliterator() method with Examples

Last Updated : 11 Jul, 2025

The spliterator() method of LinkedBlockingQueue returns a Spliterator of the same elements as LinkedBlockingQueue. 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.
Syntax: 
 

public Spliterator spliterator()


Return Value: This method returns a Spliterator over the elements in LinkedBlockingQueue.
Below programs illustrates spliterator() method of LinkedBlockingQueue class:
Program 1: Creating a Spliterator from LinkedBlockingQueue which contains names of different student of a class
 


Output: 
list of names:
Aman
Amar
Sanjeet
Rabi

 

Program 2: Creating a Spliterator from LinkedBlockingQueue which contains list of Employees objects.
 


Output: 
No of Employees = 2
-----------------------------
Employee Name : Aman
Employee Position : Blogger
Employee Salary : 100000
-----------------------------
Employee Name : Amar
Employee Position : Manager
Employee Salary : 99000

 

Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/LinkedBlockingQueue.html#spliterator--
 

Comment