VOOZH about

URL: https://www.geeksforgeeks.org/java/arraylist-vs-linkedlist-java/

⇱ ArrayList vs LinkedList in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

ArrayList vs LinkedList in Java

Last Updated : 29 May, 2026

ArrayList and LinkedList are two commonly used classes in Java that implement the List interface. Both maintain insertion order and allow duplicate elements, but they differ in memory structure, data access, and performance for insertion and deletion operations.

  • ArrayList is based on a dynamic array, while LinkedList uses a doubly linked list
  • ArrayList provides faster random access, whereas LinkedList is efficient for frequent insertions and deletions
  • Both are part of the Java Collections Framework and support generic data storage

ArrayList

ArrayList is a class in Java Collections Framework that stores elements in a sequential manner and automatically grows in size when needed. It is widely used for fast data retrieval and managing ordered collections of elements.

  • Allows storing elements of the same or different data types using generics
  • Supports index-based operations like searching, updating, and accessing elements
  • Maintains insertion order of elements during storage and retrieval

Syntax:

ArrayList<DataType> listName = new ArrayList<>();


Output
[Java, Python, C++]
Element at index 1: Python

Explanation:

  • Elements are stored in contiguous memory locations
  • Accessing elements using index is fast
  • When the internal array becomes full, a new larger array is created and elements are copied

LinkedList

LinkedList is a class in Java Collections Framework that stores elements as interconnected nodes instead of a continuous memory structure. It is mainly used when frequent insertion and deletion operations are required.

  • Implements both List and Deque interfaces in Java
  • Allows efficient insertion and deletion of elements from both ends
  • Maintains insertion order and supports duplicate elements

Syntax:

LinkedList<DataType> listName = new LinkedList<>();


Output
[Java, Python, C++]
First element: Java

Explanation:

  • Each element is stored as a node. Every node contains:
  • Data
  • Reference to previous node
  • Reference to next node
  • No shifting of elements during insertion or deletion

ArrayList vs LinkedList

FeatureArrayListLinkedList
DefinitionA resizable array implementation of the List interfaceA doubly-linked list implementation of the List interface
Data StorageStores elements in contiguous memory locationsStores elements as nodes linked using pointers
Access TimeFast random access using index (O(1))Slower random access (O(n))
Insertion/DeletionSlower in middle or beginning (O(n)), faster at endFaster for insertion/deletion anywhere (O(1) if position known)
Memory UsageLess memory overheadMore memory due to storing pointers
IterationFaster iteration using index-based loopFaster iteration using iterator
Use CaseBest for frequent access and rare modificationsBest for frequent insertions and deletions
Comment