File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Performance and the fly likes Linkedlist vs Queue - what does this comment mean? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Linkedlist vs Queue - what does this comment mean?" Watch "Linkedlist vs Queue - what does this comment mean?" New topic

Linkedlist vs Queue - what does this comment mean?

Ranadhir Nag
Ranch Hand

Joined: Mar 09, 2006
Posts: 138
Read the following:
'The LinkedList class is often used to store a list, or queue, of work elements --
tasks waiting to be executed. However, the List interface offers far more flexibility
than is needed for this common application, which in general only inserts elements
at the tail and removes elements from the head. But the requirement to support the
full List interface means that LinkedList is not as efficient for this task as it might
otherwise be. The Queue interface is much simpler than List -- it includes only
put() and take() methods, and enables more efficient implementations than

What is the Queue providing us that the LinkedList doesnt?
Why and in what circumstances will I go for a Queue?
In-depth analytical comments will be much appreciated.
Stephan van Hulst

Joined: Sep 20, 2010
Posts: 4626

Well, like the text explained, Queue is an interface that doesn't require its implementing class to support as many features as the LinkedList class does. The implementing class will be free in how it implements the put and take methods, so this can be done easier and more efficiently.

Queue doesn't offer you anything that LinkedList doesn't, because LinkedList is-a Queue. A very efficient implementation of the Queue interface is the ArrayDeque class.

You use a Queue when you need to perform first-in-first-out operations. An example is a queue of tasks waiting to be handled. New tasks can be added to the back of the queue, and whatever handles the tasks takes old tasks from the front of the queue.

The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
I agree. Here's the link:
subject: Linkedlist vs Queue - what does this comment mean?
jQuery in Action, 3rd edition