Queue Interface- Notes By ShariqSP

Queue Interface in Java

The Queue interface in Java represents a collection of elements where elements are inserted and removed according to the first-in-first-out (FIFO) principle. It is typically used to process elements in the order they were added.

Methods:

  • add(E element): Adds the specified element to the queue.
  • remove(): Removes and returns the head of the queue.
  • peek(): Retrieves, but does not remove, the head of the queue.
  • isEmpty(): Returns true if the queue contains no elements.
  • size(): Returns the number of elements in the queue.
  • clear(): Removes all elements from the queue.

Implementation Classes:

The Queue interface has several implementation classes in Java:

  • LinkedList: Doubly linked list implementation of the Queue interface.
  • PriorityQueue: Unbounded priority queue based on a priority heap.