I want to have a limited queue with FIFO. So if maximum size of queue exceeds, first element(s) are removed.
FIFO queue with google collections:
Queue<Integer> fifo = EvictingQueue.create(2);
fifo.add(1);
fifo.add(2);
fifo.add(3);
System.out.println(fifo); // prints [2, 3]
FIFO queue with apache collections:
// FIFO-queue works with apache collections
Queue<Integer> fifo2 = new CircularFifoQueue<>(2);
fifo2.add(1);
fifo2.add(2);
fifo2.add(3);
System.out.println(fifo2); // prints [2, 3]
FIFO queue with JDK collections:
Queue<Integer> fifo3 = new ArrayBlockingQueue<>(2);
fifo3.offer(1);
fifo3.offer(2);
fifo3.offer(3);
System.out.println(fifo3); // prints [1, 2]
ArrayBlockingQueue
does not work as FIFO, it only stops inserting elements if queue is full.
Are there any JDK FIFO queues working similar to EvictingQueue
or CircularFifoQueue
?
And if JDK does not provide something like that, which one should I take: EvictingQueue
or CircularFifoQueue
?
Which is better implemented?
(Please dont provide example implementation of fifo queues, I want to use lib, preferable only JDK)