ArrayList vs LinkedList in Java

ArrayList vs. LinkedList

Arraylist is an index based Data Structure. While using Arraylist for searching or getting an element from an array with index is pretty fast.

ArrayList provides O(1) performance to get(index) method but remove is costly as you may need to rearrange all the elements.

While, LinkedList doesn’t provide random or index based access and you need to iterate over each element to retrieve any element which is order n and hence performance of it is O(n).

LinkedList has more memory overhead than ArrayList because ArrayList’s each index holds actual object while LinkedList each node holds both data and address of Next & Previous node as well.

Additions/Deletion of new elements are easy and fast in LinkedList as compare to ArrayList as there is no risk of resizing Arrays and Copying content to new Array if Array gets full makes adding into Arraylist of O(n) performance in worst case. While adding is O(1) operation in LinkedList. ArrayList also needs to update indexes if you add something in between array of Objects.

Leave a Reply