Difference between ArrayList and LinkedList
ArrayList | LinkedList |
---|---|
1) ArrayList internally uses dynamic array to store the elements. | LinkedList internally uses doubly linked list to store the elements. |
2) Manipulation with ArrayList is slow because it internally uses array. If any element is removed from the array, all the bits are shifted in memory. | Manipulation with LinkedList is faster than ArrayList because it uses doubly linked list so no bit shifting is required in memory. |
3) ArrayList search operation is pretty fast compared to the LinkedList search operation. ArrayList gives the performance of O(1) |
LinkedList search operation is pretty slow compared to the ArrayList search operation. LinkedList gives the performance of O(n) |
4) ArrayList element deletion is slow compared to LinkedList .ArrayList deletion operation gives O(n) in worst case (while removing first element) and O(1) in best case (While removing last element). | LinkedList element deletion is faster compared to ArrayList.LinkedList deletion operation gives O(1) performance |
5) ArrayList add method gives O(n) performance |
LinkedList add method gives O(1) performance |
6)The memory consumption is low in case of ArrayList because ArrayList maintains indexes and element data | The memory consumption is high in case of LinkedList because LinkedList maintains element data and two pointers for neighbor nodes |
7) ArrayList is better for storing and accessing data. | LinkedList is better for manipulating data. |
Similarities between ArrayList and LinkedList
- Both ArrayList and LinkedList are implementation of List interface.
- Both maintain the elements insertion order means display element in the same order in which the elements are inserted into the List.
- Both ArrayList and LinkedList are non-synchronized and can be made synchronized explicitly by using
Collections.synchronizedList
method.