In Java 21 and later, addLast(e) appends an element to the end of an ArrayList, so it becomes the last element at index size() - 1. Nothing else moves.
Its effect is the same as the classic add(e), with one difference: addLast returns void, while add(e) returns true. The name exists so that List, Deque, and LinkedHashSet share the same sequenced-collection methods.
An instance method of java.util.ArrayList, added in Java 21. It was added to List through the new SequencedCollection interface, and ArrayList overrides it.
Java 21+ only.
addLast() comes from the SequencedCollection interface added in Java 21 (JEP 431). The examples on this page need JDK 21 or newer; on Java 8, 11, or 17 the call fails to compile with "cannot find symbol". On older versions, use add(e).
Syntax
Call addLast with the element to append (Java 21+).
Java
// Java 21+
List<String> list = new ArrayList<>(Arrays.asList("a", "b"));
list.addLast("c"); // [a, b, c]
list.add("d"); // [a, b, c, d] (works on every Java version)
Call
What it does
list.addLast(e)
Java 21+: appends e; returns nothing.
list.add(e)
Appends e and returns true; any Java version.
list.add(list.size(), e)
The indexed form of the same append.
list.addFirst(e)
Java 21+: inserts at the other end.
Appending is constant time on average: most calls just write into a free slot of the internal array, and only occasionally does the array have to grow.
Library declarations
Java
// java.util.ArrayList<E> (since Java 21)
public void addLast(E element)
// Declared in SequencedCollection<E> and List<E> (Java 21)