为什么ArrayDeque比LinkedList更好 [英] Why is ArrayDeque better than LinkedList

查看:595
本文介绍了为什么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.

这篇关于为什么ArrayDeque比LinkedList更好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆