wood burning stoves*
The moose likes Beginning Java and the fly likes Best implementation for Queue interface. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Best implementation for Queue interface." Watch "Best implementation for Queue interface." New topic
Author

Best implementation for Queue interface.

John Landon
Ranch Hand

Joined: Sep 25, 2008
Posts: 227
What would be best implementation for this interface?
I'll probably need thread safe. Is there already one? Any tips before I start?
Ryan Beckett
Ranch Hand

Joined: Feb 22, 2009
Posts: 192
If you need to choose the best way to do something, use PriorityQueue. The infamous traveling salesman problem benefits from a priority queue. In that problem the have to find the best route to a destination, and there are many possibilities. A LinkedList is good if your doing many insertions or deletions.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
There probably isn't a "best" implementation of anything, but have a look at the java.util.Queue interface, where there is a list of implementing classes. Some of them may have instructions about how to make a Queue thread-safe. There are comments about blocking queues in Queue, too.
Clyde DeSouza
Greenhorn

Joined: Mar 16, 2009
Posts: 26
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Queue.html


read the docs for the Use of the Queue!
John Landon
Ranch Hand

Joined: Sep 25, 2008
Posts: 227
I saw this. So let me rephrase. Let's say I do not need thread safe, do not care about nulls. I just want fast and the least resources if possible.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
ArrayDeque
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
or LinkedList



Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
John Landon
Ranch Hand

Joined: Sep 25, 2008
Posts: 227
that's what I thought. Thanks.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
The documentation says java.util.ArrayDeque is faster than LinkedList.
Clyde DeSouza
Greenhorn

Joined: Mar 16, 2009
Posts: 26
As garett said LinkedList would be more effective!!!
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
Campbell Ritchie wrote:The documentation says java.util.ArrayDeque is faster than LinkedList.


I hadn't seen that. Some quick tests confirm that ArrayDeque is indeed faster for add() and remove() operations than LinkedList.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
I think they have managed to keep ArrayDeque well hidden
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Best implementation for Queue interface.