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).

你可能感兴趣的:(ArrayList 与 LinkedList 在 Java 中的区别)