VOOZH about

URL: https://www.geeksforgeeks.org/java/priorityblockingqueue-iterator-method-in-java/

⇱ PriorityBlockingQueue iterator() method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

PriorityBlockingQueue iterator() method in Java

Last Updated : 11 Jul, 2025
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.
Output:
The Names are:
A
Computer
Geeks
forGeeks
Portal
Related Article : Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/PriorityBlockingQueue.html#iterator--
Comment