Queue interface basically orders the element in FIFO(First In First Out).
import java.util.*; class TestCollection12{ public static void main(String args[]){ PriorityQueuequeue=new PriorityQueue (); queue.add("A"); queue.add("B"); queue.add("V"); queue.add("D"); queue.add("M"); System.out.println("head:"+queue.element()); System.out.println("head:"+queue.peek()); System.out.println("iterating the queue elements:"); Iterator itr=queue.iterator(); while(itr.hasNext()){ System.out.println(itr.next()); } queue.remove(); queue.poll(); System.out.println("after removing two elements:"); Iterator itr2=queue.iterator(); while(itr2.hasNext()){ System.out.println(itr2.next()); } } }
head:A head:A iterating the queue elements: A B V D M after removing two elements: D M V Press any key to continue . . .