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

查看:27
本文介绍了为什么 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天全站免登陆