Adds an element as the last element of this collection (optional operation). After this operation completes normally, the given element will be a member of this collection, and it will be the last element in encounter order.
Examples
package com.logicbig.example.arraylist;
import java.util.*;
public class AddLastExample {
public static void main(String... args) { // Add to end (Java 21+, same as add()) ArrayList<String> list = new ArrayList<>(Arrays.asList("A", "B")); list.addLast("C"); System.out.println("After addLast: " + list); } }