See the documentation for ArrayList#remove(int), as in the following syntax:

list.remove(list.size() - 1)

Here is how it's implemented. elementData does a lookup on the backing array (so it can cut it loose from the array), which should be constant time (since the JVM knows the size of an object reference and the number of entries it can calculate the offset), and numMoved is 0 for this case:

public E remove(int index) {
    rangeCheck(index); // throws an exception if out of bounds

    modCount++;        // each time a structural change happens
                       // used for ConcurrentModificationExceptions

    E oldValue = elementData(index);

    int numMoved = size - index - 1;
    if (numMoved > 0)
        System.arraycopy(elementData, index+1, elementData, index,
                         numMoved);
    elementData[--size] = null; // Let gc do its work

    return oldValue;
}
Answer from Nathan Hughes on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ removing-last-element-from-arraylist-in-java
Removing last element from ArrayList in Java - GeeksforGeeks
July 12, 2025 - We can use the remove() method of ArrayList container in Java to remove the last element. ArrayList provides two overloaded remove() method: remove(int index) : Accept index of the object to be removed.
Discussions

apex - How to remove last element from a List<String> - Salesforce Stack Exchange
I have a requirement to exclude last element from a list. For example if my list is like this: List str=new List {'2023, 2024, 2025, 2026, 2027'}; I need a new list which More on salesforce.stackexchange.com
๐ŸŒ salesforce.stackexchange.com
June 28, 2023
java - IndexOutOfBoundsException when removing the last element of a list using list.remove(list.size()) - Stack Overflow
I've been tasked to do the below in a newbie Java tutorial on ArrayList: // 1) Declare am ArrayList of strings // 2) Call the add method and add 10 random strings // 3) Iterate through all the elem... More on stackoverflow.com
๐ŸŒ stackoverflow.com
May 23, 2017
java - Removing the last element of an ArrayList - Stack Overflow
I'm new to Java and I'm stuck with an exercise I've been trying to solve for over a week now and I don't know what I'm doing wrong. I need to delete the last elements of an ArrayList, an integer in this case. The problem is that when I run the test, it still returns the old values. Copypublic static void removeLastOccurrence(int x, ArrayList list... More on stackoverflow.com
๐ŸŒ stackoverflow.com
java - How to remove last element of arraylist - Stack Overflow
I am trying to remove the last element of arraylist after every 10 minutes. More on stackoverflow.com
๐ŸŒ stackoverflow.com
November 23, 2016
๐ŸŒ
Xenovation
xenovation.com โ€บ home โ€บ blog โ€บ java โ€บ how to remove the last element from list in java?
How to remove the last element from List in Java? (ArrayList, LinkedList, Vector)
June 24, 2020 - You do not care what the last element is. You simply want to remove the last entry. public Object removeLastElementWithReturn(List<?> pList) { Object lResult = null; // get the index of the last entry from the list int lLastIndex = -1; if (pList.isEmpty()) { // nothing to remove } else { lLastIndex = pList.size() - 1; // the the reference of the removed element lResult = pList.remove(lLastIndex); } return lResult; }
๐ŸŒ
Techie Delight
techiedelight.com โ€บ home โ€บ java โ€บ remove last element from a list in java
Remove last element from a List in Java | Techie Delight
July 7, 2026 - In this quick article, weโ€™ll see how to remove the last element of a list in Java.. We can use the `remove()` method of the `List` interface, which removes an element at the specified position in the list.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java list โ€บ removing an element from an arraylist
Removing an Element From an ArrayList | Baeldung
April 4, 2025 - Next, letโ€™s see how to remove some elements from the sport List. ArrayList has two available methods to remove an element, passing the index of the element to be removed, or passing the element itself to be removed, if present.
๐ŸŒ
Java Guides
javaguides.net โ€บ 2024 โ€บ 06 โ€บ java-arraylist-removelast-method.html
Java ArrayList removeLast() Method
June 11, 2024 - Attempting to remove the last element from an empty ArrayList will throw a NoSuchElementException. It's important to handle this case properly. import java.util.ArrayList; import java.util.List; import java.util.NoSuchElementException; public class RemoveLastWithExceptionHandling { public static void main(String[] args) { List<String> list = new ArrayList<>(); // Remove the last element with exception handling try { String removedElement = ((ArrayList<String>) list).removeLast(); System.out.println("Removed element: " + removedElement); } catch (NoSuchElementException e) { System.out.println("Error: " + e.getMessage()); } } }
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ linkedlist-removelast-method-in-java
LinkedList removeLast() Method in Java - GeeksforGeeks
July 11, 2025 - In Java, the removeLast() method of LinkedList class is used to remove and return the last element of the list.
Find elsewhere
๐ŸŒ
Quora
quora.com โ€บ How-do-you-remove-the-first-and-last-elements-from-a-Java-List
How to remove the first and last elements from a Java List - Quora
Answer (1 of 2): Youโ€™re not specifying the list type to be used. The most efficient way to remove the head and tail nodes of a list depends on the concrete list. The general solution (ignoring bound checks for now) is to do the following: [code]List list = ...; list.remove(0); list.remov...
๐ŸŒ
Reactgo
reactgo.com โ€บ home โ€บ how to remove the last element of an arraylist in java
How to remove the last element of an ArrayList in Java | Reactgo
December 24, 2022 - Consider, we have a following ArrayList: List<Integer> prices = new ArrayList<>(Arrays.asList(1, 2, 3, 4)); To remove the last element of a ArrayList, we can use the list.remove() method by passing its index list.size()-1 as an argument to it.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ java โ€บ util โ€บ linkedlist_removelast.htm
Java LinkedList removeLast() Method
The Java LinkedList removeLast() method retrieves and removes the last element of this linkedList.
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ ref_linkedlist_removelast.asp
Java LinkedList removeLast() Method
import java.util.LinkedList; public class Main { public static void main(String[] args) { LinkedList<String> cars = new LinkedList<String>(); cars.add("Volvo"); cars.add("BMW"); cars.add("Ford"); cars.add("Mazda"); // Use removeLast() to remove ...
๐ŸŒ
BeginnersBook
beginnersbook.com โ€บ 2014 โ€บ 07 โ€บ java-remove-first-and-last-element-from-linkedlist-example
Java โ€“ Remove first and last element from LinkedList example
September 11, 2022 - 2) public E removeLast(): Removes and returns the last element from this list. Complete Code: import java.util.LinkedList; public class RemoveExample { public static void main(String[] args) { // Create a LinkedList LinkedList<String> linkedlist = new LinkedList<String>(); // Add elements to ...
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ ref_arraylist_remove.asp
Java ArrayList remove() Method
If a value is specified and multiple elements in the list have the same value then only the first one is deleted. If the list contains integers and you want to delete an integer based on its value you will need to pass an Integer object. See More Examples below for an example. ... T refers to the data type of items in the list. Remove an integer from the list by position and by value: import java.util.ArrayList; public class Main { public static void main(String[] args) { ArrayList<Integer> list = new ArrayList<Integer>(); list.add(5); list.add(8); list.add(9); list.add(1); list.remove(Integer.valueOf(1)); // Remove by object list.remove(1); // Remove by index System.out.println(list); } }
๐ŸŒ
w3resource
w3resource.com โ€บ java-exercises โ€บ collection โ€บ java-collection-linked-list-exercise-13.php
Java - Remove first and last element from a linked list
Write a Java program to remove the head and tail of a linked list using the poll() and pollLast() methods. Write a Java program to implement a method that simultaneously removes and returns both the first and last elements from a linked list.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ java-list-remove-methods-arraylist-remove
How To Use remove() Methods for Java List and ArrayList | DigitalOcean
Learn how to use the remove() method in Javaโ€™s List and ArrayList interfaces with examples for removing by index or object.