![]() |
VOOZH | about |
The iterator() method of LinkedBlockingQueue returns an iterator of the same elements, as this LinkedBlockingQueue, in a proper sequence. The elements returned from this method contains all the elements in order from first(head) to last(tail) of LinkedBlockingQueue. The returned iterator is weakly consistent.
Syntax:
public Iterator<E> iterator()
Return Value: The method returns the iterator having same elements as present in LinkedBlockingQueue in order from first(head) to last(tail).
Below programs illustrates iterator() method of LinkedBlockingQueue class:
Program 1: Creating an Iterator from LinkedBlockingQueue which contains names of different student of a class.
list of names: John Tom Clark Kat
Program 2: Creating an Iterator from LinkedBlockingQueue which contains list of Employees.
list of Employees: ************************* Employee Name : Sachin Employee Position : Developer Employee Salary : 39000 ************************* Employee Name : Sanjeev Employee Position : Tester Employee Salary : 26000
Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/LinkedBlockingQueue.html#iterator--