When Java 6 was introduced, it was Sun's recommendation to use the Deque (pronounced "deck") for all Stack and Queue implemenations, which combines both in one collection class containing the familiar Stack and Queue methods, and to deprecate the legacy Stack and Queue classes from Java 5. JavaTools implements the Stack and Queue with the Deque.

In JavaTools a queue can simply be created with JDeque[]. It then has to be filled with elements afterwards.



However, it's also possible to create a new queue and supply initial values during creation:



JDequeSize[] returns the number of elements in the queue, and JDequeIsEmpty[] shows if the queue is empty:





A new element is added at the end of the queue with JDequeOffer[]or JDequeAdd[]:



The whole list of elements in the queue can be shown with JDequeElemsnts[]:



The type of elements that can be put in a queue can be anything: Integer, Real, String, or even List:











JDequePeek[] retrieves, but does not remove the first element of the queue:



JDequeElement[] does the same as JDequePeek[], except it throws an exception if the queue is empty.

JQueuePoll[] retrieves and removes the first element of the queue:





JDequeRemove[] does the same as JDequePoll[] except it throws an exception if the queue is empty. JDequeRemove[<queue>,<element>] removes the SPECIFIED element from the queue, if present.





With JDequeContains[] we can see if the queue contains a particular element:







JDequeClear[] completely clears the entire queue, returning an empty queue.















Note the memory-footprint the JDeque[] has on the Mathematica system: Not a single byte of data is stored in the kernel:








Compare against storing eight million integers in the Mathematica kernel:




Spikey Created with Wolfram Mathematica 7.0