Queue

The queue interface maintains the first-in-first-out FIFO order. A queue is an ordered list. For instance, classes like PriorityQueue, Deque, and ArrayDeque implements the Queue interface.

Syntax –

Queue q1 = new PriorityQueue();
Queue q2 = new ArrayDeque();
Queue q3 = new Deque();

Types of Queue –
  • PriorityQueue –
    • The PriorityQueue class implements the Queue interface.
    • In addition, it holds the elements or objects to process them by their priorities.
    • However, PriorityQueue doesn’t allow us to store null values in the queue.
    • Eg –
      • PriorityQueue queue=new PriorityQueue();
      • queue.add(“Ram”);
  • Deque –
    • Deque interface extends the Queue interface.
    • It implements both LIFO and FIFO.
    • Deque stands for a double-ended queue.
    • In other words, it enables us to remove and add the elements from both the side.
    • Eg –
      • Deque d = new ArrayDeque();
  • ArrayDeque –
    • ArrayDeque class implements the Deque interface.
    • It is faster than ArrayList and Stack and has no capacity restrictions.
    • Eg –
      • Deque deque = new ArrayDeque();
      • deque.add(“Ram”);