views:

1099

answers:

7

I only see a Queue interface, is there no Queue class in the Java Collections?

+5  A: 

The documentation for Queue lists various implementations, including

Pick an implementation that suits your needs.

Rob
According to http://java.sun.com/j2se/1.5.0/docs/api/java/util/ArrayList.html, ArrayList does not implement Queue.
James McMahon
Yes, I realised that one when I went back to get a few links; obviously my memory is faulty.
Rob
It happens. I'd be impressed if you have the entire Java library memorized. If you had EE memorized I'd back away slowly.
James McMahon
Well, there's javax.activation, javax.annotation, javax.ejb, and...wait, where are you going? There's so much more! ;)
Rob
+15  A: 

The Javadocs give a list of classes which implement Queue.

All Known Implementing Classes:

AbstractQueue, ArrayBlockingQueue, ArrayDeque, ConcurrentLinkedQueue, DelayQueue, LinkedBlockingQueue, LinkedBlockingDeque, LinkedList, PriorityBlockingQueue, PriorityQueue, SynchronousQueue

There are also some subinterfaces which you might find useful:

All Known Subinterfaces:

BlockingDeque<E>, BlockingQueue<E>, Deque<E>

Michael Myers
Wonder why people dont go to JavaDocs :P +1
Perpetualcoder
isnt Stack Overflow faster than google?
01
For the really lazy people, I'm going to note that all the ones with DeQue are double-ended queues.
R. Bemrose
To be precise: http://java.sun.com/javase/6/docs/api/java/util/Deque.html
Michael Myers
+1 for linking all those implementations. :)
cletus
+8  A: 

Queue has multiple implementations: from the API:

All Known Implementing Classes:

AbstractQueue, ArrayBlockingQueue, ArrayDeque, ConcurrentLinkedQueue, 
DelayQueue, LinkedBlockingDeque, LinkedBlockingQueue, LinkedList, 
PriorityBlockingQueue, PriorityQueue, SynchronousQueue

Note that AbstractQueue isn't a concrete class.

Some of these are from the package concurrent, so if you're implementing a jobqueue or something similar, you should go for ConcurrentLinkedQueue or PriorityBlockingQueue (for an heap) for ex.

akappa
+2  A: 

http://java.sun.com/javase/6/docs/api/java/util/Queue.html -- see section "All Known Implementing Classes". There are a variety of implementations which are suitable for different purposes.

Dave Costa
+3  A: 

As well as using the API docs to find "all known implementing classes", there are often other non-public implementation that are nevertheless available through the public API (only without requiring reams of pointless documentation). If you click on "use" you will also find Collections.asLifoQueue (Deque is already a Queue, but it is FIFO rather than a stack).

Tom Hawtin - tackline
Every so often, I rediscover the "Use" pages and think, "Hey, this is great!" And then I forget them again.
Michael Myers
The "use" pages don't have the greatest of UIs.
Tom Hawtin - tackline
+1  A: 

Although the answers sound kind of scornful, They are actually being pretty cool by teaching you how to fish. A Queue is simply a way to look at a collection, so many collections may implement it. As well, things that act like collections but with specific other logic (like thread queues) might use the same interface.

Knowing where to look at the javadocs is a big help. I'm sure you looked but just didn't think to look at the implementations. Live and learn.

Sometimes you may also have to chase down sub-class/extends lists. Like if you looked at Queue and saw AbstractQueue, you might want to see what classes implement that.

I'll get rid of one of your -1s for ya :)

Bill K
A: 

Import java.util.Queue;

just that

Enqueue function == Queue_Object.add(input_value);

Dequeue function == Queue_Object.pull(); //return the value and delete it from queue

FoOzA