• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Linkedlist vs Queue - what does this comment mean?

Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Saloon Keeper
Posts: 15555
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
    Bookmark Topic Watch Topic
  • New Topic