Working with Queue Data Structure

In queues, elements are stored and accessed in First In, First Out manner. That is, elements are added from the behind and removed from the front. In Java, we must import java.util.Queue library in order to use Queues.


\begin{lstlisting}
// LinkedList implementation of Queue
Queue <String> animal1 ...
...tation of Queue
Queue <String> animal3 = new PriorityQueue<>();
\end{lstlisting}

Here, we have created objects animal1, animal2 and animal3 of classes LinkedList, ArrayDeque and PriorityQueue respectively. These objects can use the functionality of the Queue interface.