Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a collection that behaves like a Queue but allows me to get multiple elements at a time?

I am looking for a data structure that behaves like a queue (it could be a queue implementation) but allows me to get multiple elements from the collection (example: the first 15 elements of the queue).

It would be very nice if it doesn't require new dependencies.

Is there anything like that?

The closer I got during my research was the BlockingQueue with the drainTo() method, but this is not what I need.

like image 657
JSBach Avatar asked Jul 15 '15 08:07

JSBach


1 Answers

LinkedList implement queue, collection, and list.

You could poll for the head, or get a sublist for the first 15 elements, and then also removeRange to remove them.

I'd probably just poll 15 times as the sublist/removeRange are going to need to iterate over the elements somehow anyway, therefore the perfromance will be similar.

like image 107
NimChimpsky Avatar answered Oct 11 '22 11:10

NimChimpsky