PriorityQueue class iterator()method example
Returns an iterator over the elements in this queue.
PriorityQueue class iterator()method example. This example shows you how to use iterator()method.This method Returns an iterator over the elements in this queue.
Here is the code:-
/**
* @Program that Returns an iterator over the elements in this queue.
* IteratorClass.java
* Author:-RoseIndia Team
* Date:-28-May-2008
*/
import java.util.*;
public class IteratorClass {
public static void main(String[] args) {
//Creating a PriorityQueue
PriorityQueue p = new PriorityQueue();
//Adding element to the queue
p.add("Girish");
p.add("Tewari");
p.add("A");
p.add("B");
p.add("C");
//Creating an Iterator Interface
Iterator i = p.iterator();
System.out.println("Queue is: ");
while (i.hasNext()) {
// Returns an iterator over the elements in this queue.
System.out.print(i.next()+"\t");
}
}
} |
Output of the program:-
Queue is:
A B Girish Tewari C |
|