Java ArrayList Methods

Beginner
6 min read
Updated: Nov 2026
31 method guides
Method index

About This Index

This page is the Java ArrayList Methods index. Each row links to a full guide with syntax, parameters, return value, three runnable examples, and FAQs. Every example is a complete Java class with a main method and fixed data, so the output shown is the output you get.

Learn what an ArrayList is on the ArrayList hub. Use this page when you need a specific method such as add(), get(), or remove(). The examples compile on Java 8 and later, except on the six Java 21 pages listed below.

Indexes start at 0.

The first element of an ArrayList is at index 0 and the last at size() - 1. Printing a list shows its elements in index order, like [a, b, c]. The methods addFirst(), addLast(), getFirst(), getLast(), removeFirst(), and removeLast() need Java 21 or newer.

How to Call an ArrayList Method

Every method here is an instance method, so you call it on your list variable:

Java
import java.util.ArrayList;
import java.util.List;

List<String> list = new ArrayList<>();
list.add("b");                       // [b]
list.add(0, "a");                    // [a, b]
list.add("c");                       // [a, b, c]
String second = list.get(1);         // "b"
list.set(1, "B");                    // [a, B, c]
int count = list.size();             // 3

Java ArrayList Methods Table

All method guides in this Java tutorial series (31 tutorials), grouped by purpose.

Add elements

4 methods

Append at the end, insert at an index, or add a whole collection. The list grows by itself; addFirst and addLast need Java 21.

MethodDescriptionTutorial
add()Append an element, or insert one at an index.Try it
addAll()Add every element of another collection.Try it
addFirst()Insert an element at the front (Java 21+).Try it
addLast()Append an element at the end (Java 21+).Try it

Read and replace

5 methods

Read an element by index or at either end, replace one element, or replace every element with a function.

MethodDescriptionTutorial
get()Read the element at an index.Try it
getFirst()Read the first element (Java 21+); throws if empty.Try it
getLast()Read the last element (Java 21+); throws if empty.Try it
set()Replace the element at an index.Try it
replaceAll()Replace every element using a function (Java 8+).Try it

Remove elements

7 methods

Remove by index, by value, at either end, by another collection, by a condition, or everything at once.

MethodDescriptionTutorial
remove()Remove one element by index or by value.Try it
removeFirst()Remove and return the first element (Java 21+).Try it
removeLast()Remove and return the last element (Java 21+).Try it
removeAll()Remove every element found in another collection.Try it
retainAll()Keep only elements found in another collection.Try it
removeIf()Remove every element that matches a condition (Java 8+).Try it
clear()Remove all elements at once.Try it

Iterate

4 methods

Walk the elements in index order, go backwards, edit while looping, or split the list for streams.

MethodDescriptionTutorial
iterator()Walk the list and remove safely while looping.Try it
listIterator()Iterate both ways and edit while looping.Try it
forEach()Run an action for every element (Java 8+).Try it
spliterator()Split the list for streams and parallel work (Java 8+).Try it

Sort, view, and copy

4 methods

Sort in place, work on a range through a view, or copy the elements into a new list or an array.

MethodDescriptionTutorial
sort()Sort the list in place with a Comparator (Java 8+).Try it
subList()Get a live view of a range of indexes.Try it
clone()Make a shallow copy of the list.Try it
toArray()Copy the elements into an array.Try it

Size and capacity

4 methods

Count the elements, check for an empty list, or manage the internal array that holds them.

MethodDescriptionTutorial
size()Count the elements in the list.Try it
isEmpty()Check whether the list has no elements.Try it
ensureCapacity()Reserve room before adding many elements.Try it
trimToSize()Shrink the capacity to the current size.Try it

Frequently Asked Questions

They are the methods of java.util.ArrayList, a list backed by a resizable array. They add, read, replace, and remove elements by index or by value, search the list, iterate over it, sort it, and copy it.
This index lists 31 guides, from add() and addAll() to toArray() and trimToSize(), grouped by what they do.
addFirst(), addLast(), getFirst(), getLast(), removeFirst(), and removeLast() come from the SequencedCollection interface added in Java 21. On older versions use add(0, e), add(e), get(0), get(size() - 1), remove(0), and remove(size() - 1).
remove(int) removes the element at an index and returns it; remove(Object) removes the first element equal to the argument and returns true or false. With a List<Integer>, list.remove(1) removes index 1, so use list.remove(Integer.valueOf(1)) to remove the value 1.
Read the Java ArrayList hub first. Then open add(), get(), set(), and remove() from the tables below.

Start with add()

Put your first elements into an ArrayList and see where they go.

add() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful