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
🌐
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.
🌐
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 - ArrayList<String> arraylist2 = new ArrayList<>(); //1 - Remove an element from the specified index position arraylist.remove(indexPosition); //2 - Remove the first occurence of element by its value arraylist.remove(element); //3 - Remove all elements of the specified collection from arraylist arraylist.removeAll(Arrays.asList(ele1, ele2, ele3)); //4 - Remove all elements matching a condition arraylist.removeIf(e -> e.contains("temp"));
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
How does an ArrayList remove an element from an array?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
6
10
March 15, 2023
Remove Element From ArrayList

Don't know if I can fix your problem, but here are a couple of notes:

  • You should first update your ArrayList and then your UI component. Reason: the user selects something with the UI component - if you modify the UI component first and then ask what the user selected so that you can remove it from the ArrayList, the selection the user made won't be there anymore. With luck it'll still somehow work out, but it's better to first do background processing and then update the UI.

  • what does your listener do? What do you need it for, especially in this single instance when the ok button is pressed?

  • you say you want your user to be able to remove an element (one), but you use removeAll(...). There is a better way to just remove one element. getItems() gives you an ObservableList. ObservableList inherits two wonderful simple remove methods from List, use one of those. As for what you want to remove: getSelectionModel() should give you a MultipleSelectionModel if you didn't change that. MultipleSelectionModel inherits getSelectedIndex() and getSelectedItem() from SelectionModel. You should use one of those with the aforementioned remove method to only remove one element.

More on reddit.com
🌐 r/learnjava
1
1
March 16, 2020
How do I make an arraylist of objects remove an object if one of its variables appears twice?
Do you need an ArrayList? Generally, if you find yourself wondering how to do something with any particular data structure and cannot easily determine how to do it, you're using the wrong data structure. I'd advise a Map, most likely a HashMap. It's a much more realistic data structure that would be used in a scenario like this. HashMap trivializes this problem with a huge efficiency boost. More on reddit.com
🌐 r/learnjava
38
20
December 9, 2019
🌐
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 - You can use the remove() method to achieve this. Here’s an example: List<Post> posts = new ArrayList<>(); // Assuming posts is populated with user posts // Remove all posts from a banned user String bannedUserId = "bannedUser123"; posts.removeIf(post -> post.getUserId().equals(bannedUserId));
🌐
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 ·
🌐
Vultr
docs.vultr.com › java › standard-library › java › util › ArrayList › remove
Java ArrayList remove() - Delete Element | Vultr Docs
November 14, 2024 - The remove() method in Java's ArrayList class is a versatile tool used to delete elements from an array list. Whether you need to remove a specific element by value or an element at a particular index, this method provides a straightforward approach.
🌐
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.
Find elsewhere
🌐
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 ...
🌐
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 - 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).
🌐
TutorialsPoint
tutorialspoint.com › java › util › arraylist_remove.htm
Java ArrayList remove() Method
The following example shows the usage of Java ArrayList remove(index) method. We're creating a ArrayList of Integers. We're adding couple of Integers to the ArrayList object using add() method calls per element.
🌐
Javatpoint
javatpoint.com › remove-an-element-from-arraylist-in-java
Remove an Element from ArrayList in Java - Javatpoint
Remove an Element from ArrayList in Java with java tutorial, features, history, variables, object, programs, operators, oops concept, array, string, map, math, methods, examples etc.
🌐
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
Earlier, I have shared how to sort ... two methods to remove an existing element from ArrayList, first by using the remove(int index) method, ......
🌐
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 - In Java, it’s straightforward to remove a specific value from a List using List.remove(). However, efficiently removing all occurrences of a value is much harder. In this tutorial, we’ll see multiple solutions to this problem, describing the pros and cons. For the sake of readability, we use a custom list(int…) method in the tests, which returns an ArrayList containing the elements we passed.
🌐
Baeldung
baeldung.com › home › java › java list › removing an element from an arraylist
Removing an Element From an ArrayList | Baeldung
April 4, 2025 - 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.
🌐
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
System.out.println("ArrayList Before : " + numbers); // Calling remove(index) numbers.remove(1); //removing object at index 1 i.e. 2nd Object, which is 2 //Calling remove(object) numbers.remove(new Integer(3)); System.out.println("ArrayList After : " + numbers); Output : ArrayList Before : [1, 2, 3] ArrayList After : [1] This time, it works, but I am afraid of lazy developers like me, which take autoboxing for granted. Now let's take a look at removing the object from ArrayList while Iterating over them. You must be familiar with Iterator in Java, before proceeding further.
🌐
Programiz
programiz.com › java-programming › library › arraylist › remove
Java ArrayList remove()
true ArrayList after remove(): [JavaScript, Python] In the above example, we have created a arraylist named languages. The arraylist stores the name of programming languages. Here, we have used the remove() method to remove the element Java from the arraylist.
🌐
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 ...
🌐
Netjstech
netjstech.com › 2015 › 08 › how-to-remove-elements-from-arraylist-java.html
How to Remove Elements From an ArrayList in Java | Tech Tutorials
October 26, 2022 - How to remove elements from an ArrayList in Java. To remove object from an ArrayList you can use remove method provided by ArrayList or the remove method provided by Iterator.
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › java-arraylist-removeobject-method-example
Java ArrayList remove(Object obj) Method example
June 1, 2024 - Lets say we have an arraylist of type integer then using list.remove(1) will remove the element at the position 1. However if you want to remove the element that has value 1 then do it like this: list.remove(Integer.valueOf(1)).