# Queue implementation in java using array and linked list

A queue is an abstract data structure that contains a collection of elements. Queue implements the FIFO mechanism i.e the element that is inserted first is also deleted first. In other words, the least recently added element is removed first in a queue. A program that implements the queue using linked list is given as follows −One of the alternative of array implementation is linked list implementation of queue. The storage requirement of linked representation of a queue with n elements is o (n) while the time requirement for operations is o (1). In a linked queue, each node of the queue consists of two parts i.e. data part and the link part. Similar to the stack, we will implement the queue using a linked list as well as with an array. But let's first discuss the operations which are done on a queue. Enqueue → Enqueue is an operation which adds an element to the queue. As stated earlier, any new item enters at the tail of the queue, so Enqueue adds an item to the tail of a queue.I want to use an ArrayList in Java and implement it as a queue. Adding to the queue should be fairly easy using queue.add("element"). Although, removing popping items out it a bit trickier. The way I thought of doing it is the following: public String pop(){ String s = queue.get(0); queue.remove(0); queue.trimToSize(); return s; }