File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

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
LinkedList.'

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
Bartender

Joined: Sep 20, 2010
Posts: 3646
    
  16

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Linkedlist vs Queue - what does this comment mean?