---
title: "Compare ArrayList and LinkedList in Java."  
description: "ArrayList and LinkedList are two commonly used implementations of the List interface in Java, each with distinct characteristics and use cases."  
author: "Ravi Vishwakarma"  
published: 2024-07-19  
updated: 2024-07-19  
canonical: https://www.mindstick.com/blog/304508/compare-arraylist-and-linkedlist-in-java  
category: "java"  
tags: ["java", "javac"]  
reading_time: 3 minutes  

---

# Compare ArrayList and LinkedList in Java.

`ArrayList` and `LinkedList` are two commonly used implementations of the `List` interface in Java, each with distinct characteristics and use cases. Here's a detailed [comparison](https://www.mindstick.com/articles/23182/comparison-maruti-suzuki-celerio-v-s-tata-tiago) of `ArrayList` and `LinkedList`, including when to use one over the other:

#### ArrayList

An array is a [collection of items](https://www.mindstick.com/forum/160239/how-to-create-a-razor-view-that-iterates-over-a-collection-of-items-and-displays-them-dynamically) stored at contiguous memory locations. The idea is to store multiple items of the same type together. However, the limitation of the array is that the size of the array is predefined and fixed.

ArrayList is a part of the **collection framework**. It is present in the **java.util** package and provides us with dynamic arrays in Java. Though, it may be slower than standard arrays but can be helpful in programs where lots of [manipulation](https://www.mindstick.com/blog/63649/77-727-microsoft-excel-2016-core-data-analysis-manipulation-and-presentation-exam) in the array is needed. We can dynamically [add and remove](https://www.mindstick.com/forum/160516/how-to-add-and-remove-a-column-in-datatable-in-dot-net-using-c-sharp) items. It automatically resizes itself. The following is an example to demonstrate the [implementation](https://www.mindstick.com/forum/33764/how-to-implementation-of-class-in-c-sharp) of the ArrayList.

```java
// Importing required classes
import java.io.*;
import java.util.*;

// Main class
class GFG {

    // Main driver method
    public static void main(String[] args)
    {
        // Creating an ArrayList of Integer type
        ArrayList<Integer> arrli
            = new ArrayList<Integer>();

        // Appending the new elements
        // at the end of the list
        // using add () method via for loops
        for (int i = 1; i <= 5; i++)
            arrli.add(i);

        // Printing the ArrayList
        System.out.println(arrli);

        // Removing an element at index 3
        // from the ArrayList
        // using remove() method
        arrli.remove(3);

        // Printing the ArrayList after
        // removing the element
        System.out.println(arrli);
    }
}
```

## Output:

```plaintext
[1, 2, 3, 4, 5]
[1, 2, 3, 5]
```

#### LinkedList

[**LinkedList**](https://www.mindstick.com/forum/159217/when-to-use-linkedlist-over-arraylist-in-java) is a linear [data structure](https://www.mindstick.com/blog/11221/simple-way-to-learn-dynamic-data-structure-in-c-language) where the elements are not stored in contiguous locations and every element is a separate object with a data part and an address part. The elements are linked using **pointers and addresses**. Each element is known as a node. Due to the dynamicity and ease of insertions and deletions, they are preferred over the arrays. The following is an example to demonstrate the implementation of the LinkedList.

```java
// Importing required classes
import java.util.*;

// Main class
class GFG {

    // main driver method
    public static void main(String args[])
    {

        // Creating an object of the
        // class linked list
        LinkedList<String> object
            = new LinkedList<String>();

        // Adding the elements to the object created
        // using add() and addLast() method

        // Custom input elements
        object.add("A");
        object.add("B");
        object.addLast("C");

        // Print the current LinkedList
        System.out.println(object);

        // Removing elements from the List object
        // using remove() and removeFirst() method
        object.remove("B");
        object.removeFirst();

        System.out.println("Linked list after "
                           + "deletion: " + object);
    }
}
```

## Output:

```java
[A, B, C]
Linked list after deletion: [C]
```

####

#### Summary

| Feature | ArrayList | LinkedList |
| --- | --- | --- |
| Data Structure | Dynamic array | Doubly linked list |
| Access Time | O(1) | O(n) |
| Insert/Remove Time | O(n) (except at the end) | O(1) (if node reference known) |
| Memory Overhead | Lower | Higher |
| Use Case | Fast access, fewer insertions/removals | Frequent insertions/removals |

**Choosing Between ArrayList and LinkedList**:

- Use `ArrayList` if you need fast access to elements and can handle the cost of occasional insertions and removals.
- Use `LinkedList` if you need frequent insertions and removals and can tolerate slower access times.

## Read more

[**When to use LinkedList over ArrayList in Java?**](https://www.mindstick.com/forum/159217/when-to-use-linkedlist-over-arraylist-in-java)

[**How to Create a LinkedList<String, int>**](https://www.mindstick.com/forum/1576/how-to-create-an-linkedlist-string-int)

[**When to use LinkedList over ArrayList?**](https://www.mindstick.com/forum/23188/when-to-use-linkedlist-over-arraylist)

---

Original Source: https://www.mindstick.com/blog/304508/compare-arraylist-and-linkedlist-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
