ArrayList in Java is a resizable array implementation from the java.util package, part of the Java Collections Framework. It dynamically adjusts its size as elements are added or removed, unlike fixed-size arrays.

Key Features

  • Dynamic Size: Grows and shrinks automatically when elements are added or removed.

  • Ordered Storage: Maintains insertion order; elements can be accessed by index (0-based).

  • Duplicate Elements: Allows duplicate values.

  • Null Values: Can store null elements.

  • Generic Type Safety: Supports generics (e.g., ArrayList<String>) for type safety at compile time.

  • Built-in Methods: Provides methods like add(), remove(), get(), set(), size(), contains(), and clear() for easy manipulation.

Basic Usage

import java.util.ArrayList;

public class Main {
    public static void main(String[] args) {
        // Create an ArrayList of Strings
        ArrayList<String> cars = new ArrayList<>();

        // Add elements
        cars.add("Volvo");
        cars.add("BMW");
        cars.add("Ford");

        // Access element
        System.out.println(cars.get(0)); // Output: Volvo

        // Modify element
        cars.set(0, "Opel");

        // Remove element
        cars.remove(0);

        // Check size
        System.out.println(cars.size()); // Output: 2

        // Loop through elements
        for (String car : cars) {
            System.out.println(car);
        }
    }
}

Performance & Trade-offs

  • Fast Access: get() and set() operations are O(1).

  • Amortized Fast Add: add() is O(1) on average.

  • Slower Middle Insert/Remove: Inserting or removing from the middle is O(n) due to shifting elements.

  • Memory Overhead: Slightly more memory than arrays due to internal array management.

When to Use

  • When the number of elements is unknown or changes dynamically.

  • When frequent additions, removals, or modifications are needed.

  • When you need built-in methods for searching, sorting, or iteration.

Note: For better performance with frequent contains, add, or remove operations, consider using HashSet or LinkedHashSet instead.

You can use the following instruction:

new ArrayList<>(Arrays.asList(array));
Answer from Tom on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › ArrayList.html
ArrayList (Java Platform SE 8 )
October 20, 2025 - Java™ Platform Standard Ed. 8 ... public class ArrayList<E> extends AbstractList<E> implements List<E>, RandomAccess, Cloneable, Serializable
🌐
W3Schools
w3schools.com › java › java_arraylist.asp
Java ArrayList
It is part of the java.util package and implements the List interface. The difference between a built-in array and an ArrayList in Java, is that the size of an array cannot be modified (if you want to add or remove elements to/from an array, you have to create a new one).
Discussions

java - Create ArrayList from array - Stack Overflow
That will be backed by the original input array, which is why you (probably) want to wrap it in a new ArrayList. 2008-10-01T14:46:38.45Z+00:00 ... Be careful with this solution. If you look, Arrays ISN'T returning a true java.util.ArrayList. It's returning an inner class that implements the ... More on stackoverflow.com
🌐 stackoverflow.com
Java: Is Arraylist better than Arrays?
The biggest difference is that you can add to and remove from a list, whereas arrays have a fixed size. More on reddit.com
🌐 r/learnprogramming
28
19
June 23, 2024
Is using ArrayList good practice for a regular software engineering job?
How often do software engineers use ArrayList? Always. I write readable, maintainable code. I'm not "l33t h4xor", I'm fucking working. More on reddit.com
🌐 r/java
232
126
August 10, 2021
How do I create a 2d ArrayList in java?
Fast and easy solution: You can make an arraylist of an object which is of type arraylist More on reddit.com
🌐 r/learnjava
16
26
June 25, 2020
🌐
GeeksforGeeks
geeksforgeeks.org › java › arraylist-in-java
ArrayList in Java - GeeksforGeeks
ArrayList in Java is a resizable array provided in the java.util package.
Published   1 month ago
🌐
Octoperf
blog.octoperf.com › java-arraylist
Java ArrayList - OctoPerf
Java's ArrayList is a dynamic array implementation of the List interface. Learn how and when an ArrayList should be used.
🌐
Reddit
reddit.com › r/learnprogramming › java: is arraylist better than arrays?
r/learnprogramming on Reddit: Java: Is Arraylist better than Arrays?
June 23, 2024 -

I've been programming in Java for 10 months now (as a subject in school) and i was always curious whats the biggest difference between Areays and Arraylist. I know that if i had an Arraylist named 'list' and i wrote System.out.print(list) it will print all the things that the list contains. Something that Arrays can't do that easily. But whats the actually biggest difference?

Find elsewhere
🌐
ThoughtCo
thoughtco.com › using-the-arraylist-2034204
How to Use an 'ArrayList' in Java
July 3, 2019 - Standard arrays in Java are fixed in the number of elements they can have. If you want to increase of decrease the elements in an array then you have to make a new array with the correct number of elements from the contents of the original array. An alternative is to use the ArrayList class.
🌐
Java Development Journal
javadevjournal.com › home › introduction to the java arraylist
Introduction to the Java ArrayList | Java Development Journal
June 15, 2021 - The ArrayList class is the part of Java Collection Framework. This class implements the List interface provided by the Collection framework. This is a high level hierarchy for the Array list.
🌐
DEV Community
dev.to › tacomanick › java-arraylists-a-dead-easy-tutorial-for-absolute-beginnners-8ig
Java ArrayLists: A Dead Easy Tutorial For Absolute Beginnners - DEV Community
December 14, 2019 - This rather cryptic definition basically means that an ArrayList is a class that defines the empty methods in the List interface. Thankfully, the Java gods were kind enough to define these methods for us mere mortals, so ArrayLists aren't as complicated as they initially seem.
🌐
Baeldung
baeldung.com › home › java › java collections › guide to the java arraylist
Guide to the Java ArrayList | Baeldung
December 14, 2024 - We showed how to create an ArrayList instance, and how to add, find, or remove elements using different approaches. Furthermore, we showed how to add, get, and remove the first, or the last element using sequenced collections introduced in Java 21.
🌐
Programiz
programiz.com › java-programming › library › arraylist
Java ArrayList Methods | Programiz
Java has a lot of ArrayList methods that allow us to work with arraylists. In this reference page, you will find all the arraylist methods available in Java.
🌐
Vaia
vaia.com › java arraylist
Java Arraylist: Definition & Examples | Vaia
November 14, 2023 - Java ArrayList is a resizable array implementation in the Java Collections Framework that allows dynamic storage and easy insertion, removal, and modification of elements. Unlike standard arrays, ArrayLists automatically adjust their capacity when elements are added or removed, making them ...
🌐
CodingNomads
codingnomads.com › what-is-a-java-arraylist
What is a Java ArrayList? How to use a Java ArrayList?
ArrayLists in Java are similar to standard Arrays, but they differ in that they do not have a fixed size and they have a number of useful helper methods.
🌐
Coderanch
coderanch.com › t › 464780 › java › ArrayList-Integer
new ArrayList ({1,2,3,4}) (Beginning Java forum at Coderanch)
October 1, 2009 - programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums · this forum made possible by our volunteer staff, including ... ... Hello, How can I add some values in a List while I instantiate it? Something like: List<Integer> a = new ArrayList<Integer>({1,2,3,4}); I do not want to use: a.add(1); a.add(2); ..
🌐
Sololearn
sololearn.com › en › Discuss › 2706076 › javaarraylist-problem-
Java.arraylist problem | Sololearn: Learn to code for FREE!
Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.
🌐
DEV Community
dev.to › iammtander › what-i-learned-fro-head-first-java-arrays-and-arraylist-2pgo
What I learned from Head First Java: Arrays and ArrayList - DEV Community
April 3, 2025 - Once assembled, you can't add more shelves without buying a completely new unit. An ArrayList, on the other hand, is like a magic bookshelf that automatically expands whenever you need more space. Arrays in Java are the original way to store multiple values of the same type.
🌐
Lawrence
www2.lawrence.edu › fast › GREGGJ › CMSC150 › 062ArrayLists › ArrayLists.html
Working with ArrayLists
The ArrayList class is a Java class that you can use to store lists of objects.
🌐
GeeksforGeeks
geeksforgeeks.org › java › array-vs-arraylist-in-java
Array vs ArrayList in Java - GeeksforGeeks
July 23, 2025 - In Java, an Array is a fixed-sized, homogenous data structure that stores elements of the same type whereas, ArrayList is a dynamic-size, part of the Java Collections Framework and is used for storing objects with built-in methods for manipulation.
🌐
Stanford
web.stanford.edu › class › archive › cs › cs108 › cs108.1082 › 106a-java-handouts › HO49ArrayList.pdf pdf
CS106A, Stanford Handout #49 Fall, 2004-05 Nick Parlante ArrayList
ArrayList class can store a group of many objects. This capability will greatly expand · what our programs can do. Java has a whole suite of a "Collection" classes that can store