queue in Java

Queue in Java follows a FIFO approach i.e. it orders the elements in First In First Out manner. In a queue, the first element is removed first and the last element is removed in the end. Each basic method exists in two forms: one throws an exception if the operation fails, the other returns a special value.
     |Throw exception | Return special value
----- | ----- | -----
insert | add(e) | offer(e)
remove | remove(e) | pull(e)
examine | element(e) | peek(e)

```
import java.util.*; 
class QueueExample { 
    public static void main(String args[]){ 
        PriorityQueue<String> queue=new PriorityQueue<String>(); 
        queue.add("a"); 
        queue.add("c");
        queue.add("b"); 
        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(); 
        Iterator<String> itr2=queue.iterator(); 
        while(itr2.hasNext()){
            System.out.println(itr2.next());
        }
    }
}
```
Also, the priority queue implements Queue interface. The elements of the priority queue are ordered according to their natural ordering, or by a Comparator provided at the queue construction time. The head of this queue is the least element with respect to the specified ordering.
Below are some of the methods of Java Queue interface:
Method | Description
----- | -----
 boolean add(object) | Inserts the specified element into the queue and returns true if it is a success.
 boolean offer(object) | Inserts the specified element into this queue.
 Object remove() | Retrieves and removes the head of the queue.
 Object poll() | Retrieves and removes the head of the queue, or returns null if the queue is empty.
 Object element() | Retrieves, but does not remove the head of the queue.
 Object peek() | Retrieves, but does not remove the head of this queue, or returns null if the queue is empty.