Queues are essential data structure in computer programming that follows a first in first out (FIFO) order. FIFO means the first added element in the queue will be the first element to be removed. Java provides an interface
Queue which is the part of Java framework collection.
The queue interface extends a Collection interface and represents a collection of elements awaiting processing. Queue interface provides different methods for performing different operations like insertion, extraction, deletion …etc.
Although the queue provides various methods, some of the key methods defined in the Queue interface are given below.
- offer (Object o) : This method adds an object into queue.
- peek(): Return the head element of the queue and return null if the queue is empty.
- pool() : Return and remove the head element of the queue and return null if the queue in empty
- remove(): Return and remove the head element of the queue if the queue is empty then this method raises