Collections - Queue
Collections - Queue The java.util.Queue is a subtype of java.util.Collection interface. It is an ordered list of objects with its use limited to inserting elements at the end of list and deleting elements from the start of list i.e. it follows FIFO principle. Since it is an interface, we need a concrete class during its declaration. There are many ways to initialize a Queue object, most common being- As a Priority Queue As a LinkedList Please note that both the implementations are not thread safe. PriorityBlockingQueue is one alternative implementation if you need a thread safe implementation. Operations on Queue : Add()- Adds an element at the tail of queue. More specifically, at the last of linkedlist if it is used, or according to the priority in case of priority queue implementation. peek()- To view the head of queue without removing it. Returns null if queue is empty. element()- Similar to peek(). Throws NoSuchElementException if queue is empty. remove()- Removes...