All Classes and Interface of Queue Interface (PriorityQueue, Deque, LinkedList, ArrayDeque).

 In Java, the Queue interface is a part of the Java Collection Framework. It is designed to represent a collection of data in a specific order for processing. Typically ordered by insertion (FIFO) or priority. Queue allows duplicates. Queue provides the methods for inserting, deleting, and inspecting the data.

Classes and Interface implemented the Queue - 
  1. PriorityQueue class
  2. Deque Interface (Implemented in ArrayDeque and LinkedList classes)
Implemented Queue Interface in PriorityQueue, Deque
Implemented the Queue Interface

1. PriorityQueue Class: PriorityQueue order it's element based on Natural Ordering rather than insertion.
  • Natural Ordering = Lowest value to Highest value
  • Reverse Ordering = Highest value to Lowest value
By default, is ordered the element as Lowest to Highest value. It is possible to make Highest to Lowest using Comparator.reverseOrder() method.

PriorityQueue class code example

2. Deque (Double-Ended Queue) Interface: Deque interface can be implemented in LinkedList class.
  • Allows to add and remove the element from both sides (First and Last) of the queue. 
  • Allows both LIFO and FIFO
Deque interface code example

3. LinkedList Class: 
  • LinkedList class implements the Deque interface to perform the Deque concept. This means, ordering the elements from both sides.
        Example - same as above code.

4. ArrayDeque Class: 
  • ArrayDeque also implements the Deque interface to order the elements from both sides. But ArrayDeque provides the faster performance comparatively LinkedList class.
ArrayDeque class code example


Next : Set Interface ( HashSet, LinkedHashSet, SortedSet, TreeSet)

Code >>

Post a Comment

0 Comments