In the above picture, we observe that elements are first pushed to the back of the queue, and then the elements are removed through the front. Java’s implementation of queue also supports array operations including
indexOf(). This however means that insertion and eviction operations are much slower than if implemented using a simple linked list. For instance, C++ offers significant advantages over Java’s implementation, but Java’s implementation also has its advantages.
Regardless, below is a brief overview of the methods used in Java:
We observe here that the argument type is called E which is unique to Java, employing something called Java Generics. I will not talk too much about this further, but it is somewhat similar to C++’s template parameters (and for those who are curious, templates is one of the most powerful tools in C++, allowing users to do some really crazy stuff like partial template specialization). What this allows the user to do is define the type of objects which the queue contains. For now, pretend that E is replaced by the Integer type in the Java SE library.'