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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With