What is difference between ArrayList and LinkedList ?
ArrayListis an index based data structure backed by an
Array. It provides random access to its elements with a performance equal to O(1). On the other hand, a
LinkedListstores its data as list of elements and every element is linked to its previous and next element. In this case, the search operation for an element has execution time equal to O(n).
- The Insertion, addition and removal operations of an element are faster in a
LinkedListcompared to an
ArrayList, because there is no need of resizing an array or updating the index when an element is added in some arbitrary position inside the collection.
LinkedListconsumes more memory than an
ArrayList, because every node in a
LinkedListstores two references, one for its previous element and one for its next element.
Check also our article ArrayList vs. LinkedList.