Java Queue Interface

Queue interface basically orders the element in FIFO(First In First Out).

Methods of Queue Interface

  1. public boolean add(object)
  2. public boolean offer(object)
  3. public remove()
  4. public poll()
  5. public element()
  6. public peek()

Example of ArrayDeque


	import java.util.*;

	class TestCollection12{

	public static void main(String args[]){



	PriorityQueue queue=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());

	}

	}

	}

		

	
				
				
				
						
						
						
						

Output


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 . . .