

Inserts the specified element into the queue represented by this deque This interface is a member of the Java Collections Methods, but instead inherit the identity-based versions from class Null is used as a special return value by various methodsĭeque implementations generally do not defineĮlement-based versions of the equals and hashCode Take advantage of the ability to insert nulls. That do allow null elements are strongly encouraged not to To prohibit the insertion of null elements, they are stronglyĮncouraged to do so. While Deque implementations are not strictly required Provide support for indexed access to elements. Unlike the List interface, this interface does not This interface provides two methods to remove interior Note that the peek method works equally well whenĪ deque is used as a queue or a stack in either case, elements are Stack methods are precisely equivalent toĭeque methods as indicated in the table below:Ĭomparison of Stack and Deque methods Stack Method When a deque is used as a stack, elements are pushed and popped from theīeginning of the deque. Interface should be used in preference to the legacy Stack class. Inherited from the Queue interface are precisely equivalent toĭeque methods as indicated in the following table:Ĭomparison of Queue and Deque methods Queue Methodĭeques can also be used as LIFO (Last-In-First-Out) stacks. Elements areĪdded at the end of the deque and removed from the beginning. Used as a queue, FIFO (First-In-First-Out) behavior results. This interface extends the Queue interface. The twelve methods described above are summarized in the The latter form of the insert operation isĭesigned specifically for use with capacity-restrictedĭeque implementations in most implementations, insert Special value (either null or false, depending on One throws an exception if the operation fails, the other returns a Each of these methods exists in two forms: Methods are provided to insert, remove, andĮxamine the element. This interface defines methods to access the elements at bothĮnds of the deque. They may contain, but this interface supports capacity-restrictedĭeques as well as those with no fixed size limit. Implementations place no fixed limits on the number of elements The name deque is short for "double ended queue"Īnd is usually pronounced "deck". Let's see the declaration for class.A linear collection that supports element insertion and removal atīoth ends.

However, sometimes the elements of the queue are needed to be processed according to the priority, that's where a PriorityQueue comes into action. It is already described that the insertion and deletion of objects follows FIFO pattern in the Java queue. PriorityQueue is also class that is defined in the collection framework that gives us a way for processing the objects on the basis of priority. In fact, deques support element insertion and removal at both ends. All Queues barring the Deques facilitates removal and insertion at the head and tail of the queue respectively.Those Queues that are present in the ncurrent package are known as bounded Queues.Those Queues that are present in the util package are known as Unbounded Queues.The NullPointerException is raised, if any null operation is done on the BlockingQueues.PriorityQueue, ArrayBlockingQueue and LinkedList are the implementations that are used most frequently.The Java Queue provides support for all of the methods of the Collection interface including deletion, insertion, etc.As discussed earlier, FIFO concept is used for insertion and deletion of elements from a queue.The following are some important features of a queue. It is used to retrieves, but does not remove, the head of this queue, or returns null if this queue is empty. It is used to retrieves, but does not remove, the head of this queue. It is used to retrieves and removes the head of this queue, or returns null if this queue is empty. It is used to retrieves and removes the head of this queue. It is used to insert the specified element into this queue.

It is used to insert the specified element into this queue and return true upon success. Public interface Queue extends Collection
