2

I need to implement a basic FIFO queue of objects. Whats the best built-in class for do that?

3
  • Can you explain why you need implement a basic FIFO unless this is homework? Why not use on of the many builtin implementations? Commented Feb 8, 2012 at 19:23
  • 1
    Because 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 nice Commented 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. ;) Commented Feb 9, 2012 at 15:28

2 Answers 2

8

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.
7

Read the JavaDoc for the java.util.Queue interface and pick an appropriate implementing class from the list shown.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.