FIFO-based queue implementations?

I need a simple FIFO implemented queue to store an int bundle (I don't mind if this is a generics implementation).

Anything already baked for me in java.util or in the Trove / Guava library?

+51
java collections queue
Apr 18 2018-12-18T00:
source share
5 answers

Yes. Queue

LinkedList is the most trivial concrete implementation.

+57
Apr 18 2018-12-18T00:
source share

Here is a sample code to use the java built-in FIFO queue:

 public static void main(String[] args) { Queue<Integer> myQ=new LinkedList<Integer>(); myQ.add(1); myQ.add(6); myQ.add(3); System.out.println(myQ); //1 6 3 int first=myQ.poll();// retrieve and remove the first element System.out.println(first);//1 System.out.println(myQ);//6 3 } 
+41
Sep 03 '12 at 16:59
source share

ArrayDeque is probably the fastest object queue in the JDK; Trove has a TIntQueue interface, but I don’t know where its implementations live.

+10
Apr 18 2018-12-18T00:
source share

Queue is an interface that extends Collection in Java. It has all the features needed to support the FIFO architecture.

For a specific implementation, you can use LinkedList . LinkedList implements Deque , which in turn implements Queue . All of this is part of the java.util package.

For more information on the method with an example example, see FIFO-based Queue Implementation in Java .

+3
Dec 11 '13 at 18:52
source share

Yes, these things are built into Java. Just one example here . Have a google search about queues in java, and thats it.

+2
Apr 18 '12 at 16:27
source share



All Articles