Tuesday, October 27, 2015

What is difference between ArrayList and LinkedList?



.
1.            ArrayList is an index based data structure backed by Array, so it provides random access to it’s elements with performance as O(1) but LinkedList stores data as list of nodes where every node is linked to it’s previous and next node. So even though there is a method to get the element using index, internally it traverse from start to reach at the index node and then return the element, so performance is O(n) that is slower than ArrayList.
2.    Insertion, addition or removal of an element is faster in LinkedList compared to ArrayList because there is no concept of resizing array or updating index when element is added in middle.
3.    LinkedList consumes more memory than ArrayList because every node in LinkedList stores reference of previous and next elements

No comments:

Post a Comment