![]() |
VOOZH | about |
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
list of names: Aman Amar Sanjeet Rabi
Program 2: Creating a Spliterator from LinkedBlockingQueue which contains list of Employees objects.
No of Employees = 2 ----------------------------- Employee Name : Aman Employee Position : Blogger Employee Salary : 100000 ----------------------------- Employee Name : Amar Employee Position : Manager Employee Salary : 99000