Jump to content
  • Advertisement
Sign in to follow this  
eben

[java] Java 1.5 - Queue Data Type

This topic is 4829 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was looking through the Java 1.5 api for a basic Queue implementation (something like ArrayQueue from Java 1.4) But looking at all the classes that extend the Queue interface I'm confused because none of them seem to be a basic ol' Queue. linky: http://java.sun.com/j2se/1.5.0/docs/api/java/util/Queue.html Any suggestions? thanks.

Share this post


Link to post
Share on other sites
Advertisement
What's wrong with:

Queue<MyObject> myQueue = new LinkedList<MyObject>();

That way, whenever you use myQueue, you only have access to the methods defined in the queue interface.
Also, a linked list is the ideal data structure to use to back a queue interface from an execution speed viewpoint.

Share this post


Link to post
Share on other sites
The only thing possibly faster than that would be a Circular Array Queue, which wouldn't be hard to create yourself, but the basic problem would be that you would have to know how large to make it when instantiating it. Of course, you could always "grow" it when it gets too large, but if your going to have to "grow" the thing then a LinkedList is better. The only other possible side problem with a LinkedList implementation is the added storage required by each node to hold the Link Reference. But that isn't really all to big a deal most of the time. (Heck you probably already know all this).

Another solution would be to write a class that extends ArrayList, and Implements the Queue interface. And you could do that as an annonymous class, that just forwards the Queue interface calls to the appropriate ArrayList methods calls.

L-

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!