gpt4 book ai didi

java 8 - 循环缓冲区

转载 作者:行者123 更新时间:2023-12-02 10:23:07 25 4
gpt4 key购买 nike

Java 中循环缓冲区的最佳实现是什么?我已阅读other questions但它们已经旧了,请参阅 CircularFifoBuffer Apache Commons Collections 4 中不存在这种情况。在 Java 8 中是否有一种新的、广泛接受的方法来使用循环缓冲区?

最佳答案

java.util.ArrayDeque 。该类仍然有点被忽视。

来自文档:

Resizable-array implementation of the Deque interface. Array deques have no capacity restrictions; they grow as necessary to support usage. … This class is likely to be faster than Stack when used as a stack, and faster than LinkedList when used as a queue.

Since:

1.6

文档没有直接声明它是循环的,但它确实是循环的(我刚刚检查了源代码,100%确定)。由于他们建议将其用作队列,因此不将其设为循环是没有意义的。

关于java 8 - 循环缓冲区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54185559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com