Hire QA – Specialized in QA Recruitment, Technical Interviews and Testing Solutions

What is difference between ArrayList and LinkedList?

Category: Java

ArrayList and LinkedList both implement List interface but there are some differences between them:

  • ArrayList is an index based data structure backed by Array, so it provides random access to its elements with performance as O(1) but LinkedList stores data as list of nodes where every node is linked to its 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.
  • 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.
  • LinkedList consumes more memory than ArrayList because every node in LinkedList stores reference of previous and next elements.

Leave a Reply

Your email address will not be published. Required fields are marked *