The Java.util.PriorityQueue.iterator() method is used to return an iterator of the same elements as the Priority Queue. The elements are returned in random order from what present in the Queue.
Iterator iterate_value = Priority_Queue.iterator();
Parameters: The function does not take any parameter.
Return Value: The method iterates over the elements of the queue and returns the values(iterators).
Below programs illustrate the Java.util.PriorityQueue.iterator() method:
PriorityQueue: [4, Geeks, To, Welcome, Geeks] The iterator values are: 4 Geeks To Welcome Geeks
PriorityQueue: [5, 10, 30, 20, 15] The iterator values are: 5 10 30 20 15
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.