有人可以告诉我是否有任何 java 内置循环队列包?

can someone please tell is there any java built in package for Circular Queue?

我想知道有没有java循环队列的内置包 如果它存在那么使用它的构造函数是什么?

您可以使用 apache 中的 Class CircularFifoBuffer 构建一个固定大小的缓冲区,如果已满则替换最旧的元素。

构造函数如下所示:

Buffer circularQueue = new CircularFifoBuffer(size);

来自官方文档:

public class CircularFifoBuffer extends BoundedFifoBuffer

CircularFifoBuffer is a first in first out buffer with a fixed size that replaces its oldest element if full. The removal order of a CircularFifoBuffer is based on the insertion order; elements are removed in the same order in which they were added. The iteration order is the same as the removal order.

The add(Object), BoundedFifoBuffer.remove() and BoundedFifoBuffer.get() operations all perform in constant time. All other operations perform in linear time or worse.

Note that this implementation is not synchronized. The following can be used to provide synchronized access to your CircularFifoBuffer:

查看文档:public class CircularFifoBuffer