In your case, there's no need to iterate through the list, because you know which object to delete. You have several options. First you can remove the object by index (so if you know, that the object is the second list element):

 a.remove(1);       // indexes are zero-based

Or, you can remove the first occurence of your string:

 a.remove("acbd");  // removes the first String object that is equal to the
                    // String represented by this literal

Or, remove all strings with a certain value:

 while(a.remove("acbd")) {}

It's a bit more complicated, if you have more complex objects in your collection and want to remove instances, that have a certain property. So that you can't remove them by using remove with an object that is equal to the one you want to delete.

In those case, I usually use a second list to collect all instances that I want to delete and remove them in a second pass:

 List<MyBean> deleteCandidates = new ArrayList<>();
 List<MyBean> myBeans = getThemFromSomewhere();

 // Pass 1 - collect delete candidates
 for (MyBean myBean : myBeans) {
    if (shallBeDeleted(myBean)) {
       deleteCandidates.add(myBean);
    }
 }

 // Pass 2 - delete
 for (MyBean deleteCandidate : deleteCandidates) {
    myBeans.remove(deleteCandidate);
 }
Answer from Andreas Dolk on Stack Overflow
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-list-remove-methods-arraylist-remove
How To Use remove() Methods for Java List and ArrayList | DigitalOcean
September 9, 2025 - If the element is not found in the list, the remove(Object) method does not modify the list and returns false. To avoid confusion between these methods, ensure you understand the context and the type of parameter you are passing. If you need to remove an element by its index, use remove(int). If ...
🌐
How to do in Java
howtodoinjava.com › home › collections framework › java arraylist › remove element(s) from arraylist in java
Remove Element(s) from ArrayList in Java
August 7, 2023 - We can use another super easy syntax from Java 8 stream to remove all elements for a given element value using the removeIf() method. The following Java program uses List.removeIf() to remove multiple elements from the arraylist in java by element ...
Discussions

Question and solution: How to delete or add an object to/from array list while iterating it.
Hi few days ago i was encountered a problem. While iterating an array list by a for each loop, i was trying to remove the current object in spesific… More on reddit.com
🌐 r/processing
7
9
December 28, 2022
Java how to remove element from List efficiently - Stack Overflow
Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... Best of the Heap: First post of the... What it takes to be a player in the international AI... ... Help Shape the 2026 Developer Survey! 933 What does it mean to "program to an interface"? 31 How to efficiently (performance) remove many items from List in Java... More on stackoverflow.com
🌐 stackoverflow.com
java - Remove objects from an ArrayList based on a given criteria - Stack Overflow
Using an Iterator would give you ... the list while iterating through the arraylist ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... Starting February 24, 2026: check out our new site design at... ... 0 Removing the contents of an arraylist of customized object type based on a specific comparison between the elements of the arraylist ... 1 How to return (and remove) an object from an arraylist in java based on a ... More on stackoverflow.com
🌐 stackoverflow.com
A problem with java arraylist remove method
you can't remove an item from a collection you're iterating over. You can get around this by explicitly using an Iterator and removing the item More on reddit.com
🌐 r/learnjava
7
4
November 6, 2018
🌐
Baeldung
baeldung.com › home › java › java list › remove all occurrences of a specific value from a list
Remove All Occurrences of a Specific Value from a List | Baeldung
June 27, 2025 - List.remove(E element) has a feature we didn’t mention yet: it returns a boolean value, which is true if the List changed because of the operation, therefore it contained the element.
🌐
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.
🌐
Codecademy
codecademy.com › docs › java › arraylist › .remove()
Java | ArrayList | .remove() | Codecademy
March 21, 2022 - Beginner Friendly.Beginner Friendly17 hours17 hours · An element can be removed from an ArrayList instance by being passed to the .remove() method. It can be referenced either by value ...
🌐
Vultr
docs.vultr.com › java › standard-library › java › util › ArrayList › remove
Java ArrayList remove() - Delete Element | Vultr Docs
November 14, 2024 - Using the remove() method in Java's ArrayList offers significant flexibility for managing list data by allowing elements to be removed either by their index or value. It facilitates the dynamic manipulation of list content, which is pivotal ...
Find elsewhere
🌐
Reddit
reddit.com › r/processing › question and solution: how to delete or add an object to/from array list while iterating it.
r/processing on Reddit: Question and solution: How to delete or add an object to/from array list while iterating it.
December 28, 2022 - By iterating with a classic for loop from backwards, adding or removing an object to/from the end of the list wont effect the loop. So it should be: ... I was talking with u/AgardenerCoding about the problem. And he encouraged me to post this as it may be very useful for someone else searching for an answer to same problem. ... See also the retainAll and removeAll methods in the JavaDoc. Another option is to create a new ArrayList containing all the elements you want to remove, and after the loop completes call mylist.removeAll(toRemove) (or, if you're discarding most of the list, reverse that and use mylist.retainAll(toKeep).
🌐
How to do in Java
howtodoinjava.com › home › collections framework › java arraylist › java arraylist remove(): remove a single element from list
Java ArrayList remove(): Remove a Single Element from List with Examples - HowToDoInJava
August 7, 2023 - If the list does not contain the element, the list remains unchanged. The remove() method is overloaded and comes in two forms: boolean remove(Object o) – removes the first occurrence of the specified element by value from the list.
Top answer
1 of 4
3

Use an Iterator instead and use Iterator#remove method:

for (Iterator<String> it = a.iterator(); it.hasNext(); ) {
    String str = it.next();
    if (!str.equals("foo") || !str.equals("bar")) {
        it.remove();
    }
}

From your question:

messing with for iterators is not really good practice

In fact, if you code oriented to interfaces and use List instead of ArrayList directly, using get method could become into navigating through all the collection to get the desired element (for example, if you have a List backed by a single linked list). So, the best practice here would be using iterators instead of using get.

what is the best practice to remove items from a list efficiently?

Not only for Lists, but for any Collection that supports Iterable, and assuming you don't have an index or some sort of key (like in a Map) to directly access to an element, the best way to remove an element would be using Iterator#remove.

2 of 4
2

You have three main choices:

  1. Use an Iterator, since it has that handy remove method on it. :-)

    Iterator<String> it = list.iterator();
    while (it.hasNext()) {
        if (/*...you want to remove `it.next()`...*/) {
            it.remove();
        }
    }
    
  2. Loop backward through the list, so that if you remove something, it doesn't matter for the next iteration. This also has the advantage of only calling list.size() once.

    for (int index = list.size() - 1; index >= 0; --index) {
        // ...check and optionally remove here...
    }
    
  3. Use a while loop instead, and only increment the index variable if you don't remove the item.

    int index = 0;
    while (index < list.size()) {
        if (/*...you want to remove the item...*/) {
            list.removeAt(index);
        } else {
            // Not removing, move to the next
            ++index;
        }
    }
    

Remember that unless you know you're dealing with an ArrayList, the cost of List#get(int) may be high (it may be a traversal). But if you know you're dealing with ArrayList (or similar), then...

🌐
GeeksforGeeks
geeksforgeeks.org › java › list-removeint-index-method-in-java-with-examples
List remove(int index) method in Java with Examples - GeeksforGeeks
November 29, 2024 - // Program to illustrate the // remove(int index) method import java.util.*; public class GFG { public static void main(String[] args) { // Declare an empty List of size 5 List<Integer> l = new ArrayList<Integer>(5); // Add elements to the list l.add(5); l.add(10); l.add(15); l.add(20); l.add(25); // Index from which you want to remove element int i = 2; // Initial list System.out.println("Initial List: " + l); // remove element l.remove(i); // Final list System.out.println("Final List: " + l); } }
🌐
Cscode
cscode.io › java › collections › delete elements from list
How to delete elements from List in Java | CsCode.io
In below examples we will reference ... methods like if it's an un modifiable list etc. ... List.remove(int i) method where you can pass the index of an element....
🌐
GeeksforGeeks
geeksforgeeks.org › java › remove-element-arraylist-java
How to remove an element from ArrayList in Java? - GeeksforGeeks
July 23, 2025 - Methods: There are 3 ways to remove an element from ArrayList as listed which later on will be revealed as follows: Using remove() method by indexes(default) Using remove() method by values ·
🌐
TutorialsPoint
tutorialspoint.com › how-to-remove-an-element-from-a-java-list
How to remove an element from a Java List?
May 26, 2025 - Like an array, elements in the list are stored at a specific index starting at 0. Since we can access elements in the list through their index, and we can pass this index value to the remove() method (i.e., a basic method for removing elements), which will remove the element at the specified index.
🌐
Java67
java67.com › 2014 › 03 › 2-ways-to-remove-elementsobjects-from-ArrayList-java.html
2 Ways to Remove Elements/Objects From ArrayList in Java [Example] | Java67
Suppose you have three objects in ArrayList i.e. [1,2,3] and you want to remove the second object, which is 2. You may call remove(2), which is actually a call to remove(Object) if consider autoboxing, but will be interpreted as a call to remove 3rd element, by interpreting as remove(index). I have discussed this problem earlier in my article about best practices to follow while overloading methods in Java.
🌐
TutorialsPoint
tutorialspoint.com › java › util › arraylist_remove_object.htm
Java.util.ArrayList.remove(Object) Method
... The following example shows the usage of java.util.ArrayList.remove(object) method. package com.tutorialspoint; import java.util.ArrayList; public class ArrayListDemo { public static void main(String[] args) { // create an empty array list ...
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › java-arraylist-remove-method-example
Java ArrayList remove(int index) Method example
September 11, 2022 - It removes an element and returns the same. It throws IndexOutOfBoundsException if the specified index is less than zero or greater than the size of the list (index size of ArrayList). ... package beginnersbook.com; import java.util.ArrayList; public class RemoveExample { public static void main(String args[]) { //String ArrayList ArrayList<String> al = new ArrayList<String>(); al.add("AB"); al.add("CD"); al.add("EF"); al.add("GH"); al.add("AB"); al.add("YZ"); System.out.println("ArrayList before remove:"); for(String var: al){ System.out.println(var); } //Removing 1st element al.remove(0); //Removing 3rd element from the remaining list al.remove(2); //Removing 4th element from the remaining list al.remove(2); System.out.println("ArrayList After remove:"); for(String var2: al){ System.out.println(var2); } } }