ArrayList 与 LinkedList 在 Java 中的区别

Similarity

  • Both implements List interface.

  • Both are non synchronied classes.

Differences

  1. ArrayList internaly uses dynamic array (动态数组) to store the elements, while LinkedList internally yses double linked list (双链表).

  2. Manipulation with ArrayList is slow, while LinkedList is faster, because in array if any element is removed, all the bits are shifted in memory (由于动态数组,任何对ArrayList中元素的操作都会导内存中字节位置的变换), and there there will not be bit shifting required in memory for double linked list (双链表使得对LinkedList中元素的操作不会导致内存中字节位置的变换).

  3. ArrayList class can act as a list only, because it implements List only, while LinkedList Class can act as a list and queue both, because it implements List and Deque interfaces.

  4. ArrayList is better for stroing and accessing data, while LinkedList is better for manipulating data. In other words, if want more frequent get operations than put, ArrayList is best to go, while get operations in LinkedList are costly, but put operations are good in LinkedList (换句话说,多读取,用ArrayList;多存入,用LinkedList).

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,955评论 0 10
  • 你除了变得更好以外,你别无选择。
    施施施恩baby阅读 195评论 0 0
  • 2018年5月30日、星期三、晴 今天子墨放学回家后,作业己在托辅写完。便开始作语文培优群发的作业,因为是阅读课文...
    刘子墨妈妈阅读 213评论 0 0

友情链接更多精彩内容