I only see a Queue interface, is there no Queue class in the Java Collections?
The documentation for Queue
lists various implementations, including
Pick an implementation that suits your needs.
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>
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.
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.
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).
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 :)
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