I need to implement a basic FIFO queue of objects. Whats the best built-in class for do that?
-
Can you explain why you need implement a basic FIFO unless this is homework? Why not use on of the many builtin implementations?Peter Lawrey– Peter Lawrey2012-02-08 19:23:02 +00:00Commented Feb 8, 2012 at 19:23
-
1Because i just need add items at the tail and consume it from the head. Jus wondered if there is a basic build in implementation and java.util.Queue works niceAddev– Addev2012-02-09 15:02:04 +00:00Commented Feb 9, 2012 at 15:02
-
Queue is the interface, another useful one is Deque, LinkedList is the simplest implementation. You can also add to the head and consume from the tail if you wish. ;)Peter Lawrey– Peter Lawrey2012-02-09 15:28:02 +00:00Commented Feb 9, 2012 at 15:28
Add a comment
|
2 Answers
LinkedList is as good as any for just basic FIFO operations, but there are others there that implement the Queue interface in case you need something more advanced.
1 Comment
Benj
Don't forget to declare your LinkedList (the most simple to use, IMHO) as a Queue and not as a List if you have (as me) this bad habit. Else, you will be given access only to the List Interface methods.
Read the JavaDoc for the java.util.Queue interface and pick an appropriate implementing class from the list shown.