02. Interfaces - Collection

Queue is a subinterface of Collection. This does not work that well. For example, the size() method is O(n) for quite a few of the queues in Java, such as the ConcurrentLinkedQueue. Iteration over a queue would seldom make sense. A queue would typically be a construct where we add elements and then remove them again. It can be FIFO, LIFO or some other criteria such as priority or time. However, because Queue is a subinterface of Collection, it inherits all of the baggage that we get from Collection.

I am assuming that you are already familiar with Collection. If not, have a look at our Data Structures in Java Course.