Java – a collection behaves like a queue, but allows me to get multiple elements at once?

I'm looking for a data structure that behaves like a queue (it may be a queue implementation), but allows me to get multiple elements from the collection (for example, the first 15 elements of the queue)

This would be great if no new dependencies were needed

Anything?

The closer I get to the BlockingQueue using the drawnto () method, but this is not what I need

Solution

LinkedList implements queues, collections, and lists

You can take poll as the header, or get the first 15 elements of a sublist, and then remove them with removarange

I may only poll 15 times because the sublist / removarange will need to iterate over the elements anyway, so this principle will be similar

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>