Difference between ArrayList and LinkedList in Java?

 

Difference between ArrayList and LinkedList in Java?

Difference between ArrayList and LinkedList in Java?

Difference between ArrayList and LinkedList in Java?
  • The underlying data structure is double LinkedList.
  • Insertion order is preserved.
  • Duplicate objects are allowed.
  • Heterogeneous object allowed.
  • Null insertion is possible.
  • LinkedList implements Serializable and Cloneable interface but not RandomAccess
  • LinkedList is the best choice if our frequent operation is insertion or deletion in the middle.
  • LinkedList is worst choice if our frequent operation is retrieval operations.
  • The LinkedList class in the Java Collection API library is a double linked list implementation of the List and Deque interfaces that form a generic data structure. The LinkedList object allows null to be one of the elements of the list along with its support of all optional list operations. The class provides a method that can be used to traverse the list from beginning to the end by specifying their indices, similar to array access operations. The best part of using this class that it makes using the linked data structure easy without having to worry about the difficulties involved in implementing one from scratch.

Difference between ArrayList and LinkedList

No ArrayList LinkedList
1 ArrayList is the best choice if our frequent operation is retrieval operation LinkedList is the best choice if our frequent operation is insertion or deletion in the middle
2 ArrayList is the worst choice if our frequent operation is insertion or deletion in the middle because internally several shift operation is performed. LinkedList is worst choice if our frequent operation is retrieval operation.
3 In ArrayList, the element will be stored in consecutive memory locations and hence retrieval operation will become easy. In LinkedList, the elements won’t be stored in consecutive memory locations and hence retrieval operation will become complex.

Leave a Reply

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

*