Why is ArrayDeque better than LinkedList

2019-01-10 00:15发布

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

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

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.

7条回答
Lonely孤独者°
2楼-- · 2019-01-10 00:58

Time complexity for ArrayDeque for accessing a element is O(1) and that for LinkList is is O(N) to access last element. ArrayDeque is not thread safe so manually synchronization is necessary so that you can access it through multiple threads and so they they are faster.

查看更多
登录 后发表回答