Java Reference Library →

ArrayList Methods Reference - Complete Reference with Syntax and Description

ArrayList Methods Reference - Complete Reference with Syntax and Description

Explore the complete list of Java ArrayList methods with code syntax and beginner-friendly explanations. Perfect for learners and developers.

This reference explains ArrayList Methods Reference - Complete Reference with Syntax and Description through its syntax, examples and boundaries. Use the linked course lessons when the surrounding Java concepts are unfamiliar.

  1. Use this reference

    Identify the documented behavior, read a complete example and check its inputs before applying it.

Java ArrayList Methods

add()
public boolean add(E e)
public void add(int index, E element)
Adds an element to the list or inserts it at a specified index.
addAll()
public boolean addAll(Collection c)
public boolean addAll(int index, Collection c)
Adds all elements from a collection to the list, optionally at a given position.
clear()
public void clear()
Removes all elements from the list, leaving it empty.
clone()
public Object clone()
Returns a shallow copy of the ArrayList.
contains()
public boolean contains(Object o)
Checks if the list contains a specific element.
ensureCapacity()
public void ensureCapacity(int minCapacity)
Increases the capacity of the list to ensure it can hold more elements.
forEach()
public void forEach(Consumer action)
Applies an action to each element in the list.
get()
public E get(int index)
Returns the element at the specified index.
indexOf()
public int indexOf(Object o)
Returns the index of the first occurrence of the specified element.
isEmpty()
public boolean isEmpty()
Checks if the list has no elements.
iterator()
public Iterator iterator()
Returns an iterator to traverse the list.
lastIndexOf()
public int lastIndexOf(Object o)
Returns the index of the last occurrence of the specified element.
listIterator()
public ListIterator listIterator()
public ListIterator listIterator(int index)
Returns a list iterator for the list or from a specific index.
remove()
public E remove(int index)
public boolean remove(Object o)
Removes the element at the given index or removes the first occurrence of the specified element.
removeAll()
public boolean removeAll(Collection c)
Removes all elements that are also in the specified collection.
removeIf()
public boolean removeIf(Predicate filter)
Removes all elements that satisfy the given condition.
removeRange()
protected void removeRange(int fromIndex, int toIndex)
Removes elements between the specified range of indexes.
replaceAll()
public void replaceAll(UnaryOperator operator)
Replaces each element using the specified operator.
retainAll()
public boolean retainAll(Collection c)
Keeps only the elements that are also in the specified collection.
set()
public E set(int index, E element)
Replaces the element at the given index with a new one.
size()
public int size()
Returns the number of elements in the list.
sort()
public void sort(Comparator c)
Sorts the list using the given comparator.
spliterator()
public Spliterator spliterator()
Creates a Spliterator for the list elements.
subList()
public List subList(int fromIndex, int toIndex)
Returns a view of the portion of this list between fromIndex and toIndex.
toArray()
public Object[] toArray()
public  T[] toArray(T[] a)
Returns an array containing all elements in this list.
trimToSize()
public void trimToSize()
Trims the capacity of the list to match its current size.

Using this reference

Check the example’s types, inputs and documented behavior before copying it into an application. Some APIs require external libraries, files or platform services; consult their setup notes.

Related explanations: Java Data Types - Primitive and Non-Primitive, Java Class - Blueprint of Objects, Exceptions in Java Introduction.

Supporting documentation: Official Java learning guide.

Reference checks are optional and do not count toward course progress.

    Reference library →