Differences between ArrayList
and LinkedList
can be summarized in following points:
ArrayList
internally uses a resizable-array implementation of the List interface to store the elements.LinkedList
is doubly-linked list implementation of theList
andDeque
interfaces.LinkedList
implementsDeque
interface as well, so it provides queue like FIFO functionality through methods such aspeek()
andpoll()
.ArrayList
can be created as empty list of initial capacity 10 by overloaded constructor, whileLinkedList
only constructs the empty list without any initial capacity.- Manipulation with
ArrayList
is slow in comparison toLinkedList
because it internally uses an array. If any element is removed from the array, elements need to be shifted in memory. Manipulation withLinkedList
is faster thanArrayList
because it uses a doubly linked list. - Insertions are fast in
LinkedList
as compared toArrayList
because there is no need of resizing array and copying content to new array if array gets full. Adding n elements requires O(n) time in case ofArrayList
.
While insertion operation inLinkedList
requires O(1).ArrayList
also needs to be update its index if you insert something anywhere except at the end of array. - Since
ArrayList
is backed by array, search operation based on index is pretty fast compared to theLinkedList
search operation.get(int index)
inArrayList
gives the performance of O(1) whileLinkedList
performance is O(n). - In
LinkedList
each element maintains two pointers (addresses) which points to the both neighbor elements in the list. Hence removal of element only requires change in the pointer location in the two neighbor nodes (elements) of the node which is going to be removed. While InArrayList
all the elements need to be shifted to fill out the space created by removed element.LinkedList
remove operation gives O(1) performance whileArrayList
gives variable performance: O(n) in worst case (while removing first element) and O(1) in best case (while removing last element). ArrayList
maintains indexes and element data whileLinkedList
maintains element data and two pointers for neighbor nodes hence there is memory overhead associated withLinkedList
.LinkedList
can be iterated in reverse direction usingdescendingIterator()
while there is nodescendingIterator()
inArrayList
.