Skip to main content

Posts

Showing posts with the label ArrayDeque

Queue interface in Java with examples | Which are implementation classes of Queue?

Queue interface with ArrayDeque, LinkedList, PriorityQueue Implementation classes Queue Interface (java.util.queue) Queue is child interface of  Collection Framework in Java.  Queue provides First In First Out (FIFO) order on elements. How to use Queue interface? As Queue is interface, we must have class to implements queue. See below code for Queue implementation classes. Queue priorityQueue = new PriorityQueue(); Queue arrayDqueue = new ArrayDeque(); Queue linkedList = new LinkedList();  LinkedList class is also implementation of List Interface . Methods of Queue interface : add() - Insert the element in the queue. Throws IllegalStateException if no space available. offer() - Insert the element in the queue. element() - Return head of queue. Throws an exception if queue is empty. peek() - Return head of queue. Return null if queue is empty. poll() - Remove and return head of queue. Throws and exception of queue is empty. remove() - Remove and returns head of queue. Ret...