为什么ArrayDeque比LinkedList更好

问题描述:

我试图理解为什么Java的ArrayDeque优于Java的LinkedList ,因为它们都实现了Deque接口。

I am trying to to understand why Java's ArrayDeque is better than Java's LinkedList as they both implement Deque interface.

我几乎没有看到有人在他们的代码中使用ArrayDeque。如果有人对ArrayDeque的实现方式有了更多了解,那将会很有帮助。

I hardly see someone using ArrayDeque in their code. If someone sheds more light into how ArrayDeque is implemented, it would be helpful.

如果我理解,我会更有信心使用它。我无法清楚地了解JDK实现它管理头尾参考的方式。

If I understand it, I will be more confident using it. I could not clearly understand the JDK implementation as to the way it manages head and tail references.

链接结构可能是最糟糕的在每个元素上以高速缓存未命中进行迭代的结构。除此之外,它们消耗更多内存。

Linked structures are possibly the worst structure to iterate with a cache miss on each element. On top of it they consume way more memory.

如果需要添加/删除两端,ArrayDeque明显优于链表。随机访问每个元素也是循环队列的O(1)。

If you need add/remove of the both ends, ArrayDeque is significantly better than a linked list. Random access each element is also O(1) for a cyclic queue.

链接列表唯一更好的操作是在迭代期间删除当前元素。

The only better operation of a linked list is removing the current element during iteration.