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 - Program 1: Using remove(int index). Calculate the last element's index using the size() method as: ... // Java program to delete last element of ArrayList import java.util.List; import java.util.ArrayList; public class GFG { public static void ...
Discussions

apex - How to remove last element from a List - 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 - remove last known item from ArrayList - Stack Overflow
You need to understand java generics. You have a list of ClientThread but trying to get String. You have other errors, but this one is very basic. ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... Upcoming initiatives on Stack Overflow and across the Stack Exchange network... ... 13 IndexOutOfBoundsException when removing the last element ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
November 8, 2011
java - How to delete the last element from an array? - Stack Overflow
Now I'm working with the recursive backtracking,my assignment is to find the longest path in the maze,the mass is presented as the field covered with the coordinates,and the coordinates of the wall... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
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
... M.Sc. in Software Engineering, Khaje Nasir University of Technology ยท Author has 54 answers and 79.9K answer views ยท 5y ยท The clear() method of ArrayList in Java is used to remove all the elements from a list.
๐ŸŒ
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 - The fastest way is to use the remove(pList.size()-1) of the List interface to remove the last entry. import java.util.ArrayList; import java.util.List; public class RemoveLastElementFromList { public static void main(String[] args) { List lList ...
๐ŸŒ
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. This operation modifies the LinkedList instance.
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ ref_linkedlist_removelast.asp
Java LinkedList removeLast() Method
The removeLast() method removes the last item in a list. Tip: Use the removeFirst() method to remove the first item in a list. ... T refers to the data type of items in the list. ... If you want to use W3Schools services as an educational ...
Find elsewhere
๐ŸŒ
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 ...
๐ŸŒ
Java Guides
javaguides.net โ€บ 2024 โ€บ 06 โ€บ java-arraylist-removelast-method.html
Java ArrayList removeLast() Method
June 11, 2024 - The removeLast() method is part of the ArrayList class in Java 21. It allows you to remove the last element of the list directly, simplifying the process of removing the last element without needing to handle the index manually.
๐ŸŒ
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.
๐ŸŒ
w3resource
w3resource.com โ€บ java-exercises โ€บ collection โ€บ java-collection-linked-list-exercise-13.php
Java - Remove first and last element from a linked list
May 22, 2025 - import java.util.*; public class Exercise13 { public static void main(String[] args) { // create an empty linked list LinkedList<String> l_list = new LinkedList<String>(); // use add() method to add values in the linked list l_list.add("Red"); l_list.add("Green"); l_list.add("Black"); l_list.add("Pink"); l_list.add("orange"); // print the list System.out.println("The Original linked list: " + l_list); // Remove the first element Object firstElement = l_list.removeFirst(); System.out.println("Element removed: "+ firstElement); // Remove the last element Object lastElement = l_list.removeLast();
๐ŸŒ
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.
๐ŸŒ
CodeGym
codegym.cc โ€บ java blog โ€บ java collections โ€บ how to remove an element from arraylist in java?
How to remove an element from ArrayList in Java | CodeGym
December 10, 2024 - The iterator is smarter than it may appear: remove() removes the last element returned by the iterator. As you can see, it did just what we wanted it to do :) In principle, this is everything you need to know about removing elements from an ...
๐ŸŒ
Java67
java67.com โ€บ 2015 โ€บ 06 โ€บ how-to-remove-elements-from-arraylist.html
How to Delete Objects from ArrayList in Java? ArrayList.remove() method Example | Java67
This is different than the size ... of elements is gradually reduced after removal. By using index you can easily remove the first or last element from ArrayList in Java....