Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices).
Removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged. More formally, removes the element with the lowest index i such that Objects.equals(o, get(i)) (if such an element exists). Returns true if this list contained the specified element (or equivalently, if this list changed as a result of the call).
Example of: remove(int index)

package com.logicbig.example.arraylist;
import java.util.*;
public class RemoveExample {
public static void main(String... args) {
// Remove by index and get removed element
ArrayList<String> list = new ArrayList<>(Arrays.asList("A", "B", "C", "D"));
String removed = list.remove(1);
System.out.println("Removed: " + removed);
System.out.println("Remaining list: " + list);
}
}
Output
Removed: B
Remaining list: [A, C, D]
JDK 25Example of: remove(Object o)

package com.logicbig.example.arraylist;
import java.util.*;
public class RemoveExample2 {
public static void main(String... args) {
// Remove first occurrence of element
ArrayList<String> list = new ArrayList<>(Arrays.asList("A", "B", "C", "B", "A"));
boolean removed = list.remove("B");
System.out.println("Removed B? " + removed);
System.out.println("List after removal: " + list);
}
}
Output
Removed B? true
List after removal: [A, C, B, A]
JDK 25