The
iterator() method of
PriorityBlockingQueue class Returns an iterator over the elements in this queue. The elements returned from this method do not follow any order. The returned iterator is weakly consistent.
Syntax:
public Iterator iterator()
Parameter: This method does not take any parameter.
Returns: This method returns an
iterator having same elements as present in PriorityBlockingQueue.
Below program illustrate iterator() method of PriorityBlockingQueue.
Example 1:
Output:
PrioQueue: [45616, 945645, 7564165, 6468516]
The iterator values of PriorityBlockingQueue are:
45616
945645
7564165
6468516
Example 2: To illustrate iterator() method of PriorityBlockingQueue which contains list of names.