[java] FIFO class in Java

I want to implement FIFO through a class in Java.

Does such a class already exist? If not, how can I implement my own?

NOTE

I found a class here http://www.dcache.org/manuals/cells/docs/api/dmg/util/Fifo.html, but it doesn't contain dmg.util.*. I don't know if such a package even exists.

This question is related to java fifo

The answer is


if you want to have a pipe to write/read data, you can use the http://docs.oracle.com/javase/6/docs/api/java/io/PipedWriter.html


You don't have to implement your own FIFO Queue, just look at the interface java.util.Queue and its implementations


Not sure what you call FIFO these days since Queue is FILO, but when I was a student we used the Stack<E> with the simple push, pop, and a peek... It is really that simple, no need for complicating further with Queue and whatever the accepted answer suggests.


You can use LinkedBlockingQueue I use it in my projects. It's part of standard java and quite easy to use


Try ArrayDeque or LinkedList, which both implement the Queue interface.

http://docs.oracle.com/javase/6/docs/api/java/util/ArrayDeque.html


Queues are First In First Out structures. You request is pretty vague, but I am guessing that you need only the basic functionality which usually comes out with Queue structures. You can take a look at how you can implement it here.

With regards to your missing package, it is most likely because you will need to either download or create the package yourself by following that tutorial.