What is the difference between ArrayList and LinkedList?

---Restore content begins---

Both ArrayList and LinkedList implement the List interface, but:

  ArrayList is an index-based data interface, the bottom layer is an array, and it can access elements randomly with O(1) time complexity. The LinkedList is the data stored in the list of elements, each element is connected with its previous element and the next element, and the time complexity of finding an element is O(n).

  Compared to ArrayList, LinkedList's add, find, delete, etc. operations are faster because when an element is added to any position in the collection, there is no need to recalculate the size or update the index like an array.

  LinkedList takes up more memory than ArrayList because LinkedList stores two references for each node, one to the previous element and one to the next element.

  

---End of recovery content---

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324446314&siteId=291194637