For staters. List#remove(index) returns the Object removed from the list. List#remove(Object) returns a boolean.

In this special case however. you could do .

 ArrayList<Integer> list = new ArrayList <Integer> ();
        list.add (0);
        list.add (1);
        System.out.println(list.remove(new Integer(0)));
Answer from PermGenError on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › ArrayList.html
ArrayList (Java Platform SE 8 )
July 21, 2026 - An application can use this operation to minimize the storage of an ArrayList instance.
🌐
W3Schools
w3schools.com › java › ref_arraylist_remove.asp
Java ArrayList remove() Method
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); } }
Discussions

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
How do I remove an object from an arraylist and delete it in java?
What sort of error does it give you? Also, don't use indexOf(foo) just to find the index of the thing you want to delete. Just do remove(foo). More on reddit.com
🌐 r/learnprogramming
13
5
March 11, 2021
🌐
Coderanch
coderanch.com › t › 750418 › java › Remove-element-ArrayList-List-loop
Remove the element of ArrayList and List in for-loop indexes? (Java in General forum at Coderanch)
March 22, 2022 - All of these start with a list of values from 1 to SIZE, and then remove all odd values. Try changing the value of SIZE to see how much it can affect things. Note that the differences between several options are too small to measure accurately, unless you increase SIZE quite a bit... but the crappy answers like the one given on Stack Overflow are way too slow to handle much larger lists... I tested the code you sent. Using get(index) with List is a bad thing, but it brings better performance with ArrayList.
Find elsewhere
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › java › removing-element-from-the-specified-index-in-java-arraylist
Removing Element from the Specified Index in Java ArrayList - GeeksforGeeks
March 31, 2023 - The remove(int index) method present in java.util.ArrayList class removes the element at the specified position in this list and shifts any subsequent elements to the left (i.e.
🌐
CodeGym
codegym.cc › java blog › java collections › arraylist removeall() method in java
ArrayList removeAll() method in Java
January 7, 2025 - The remove(int index) method in the ArrayList class removes the element at the specified index. The indices of subsequent elements are shifted to fill the gap.
🌐
Scaler
scaler.com › home › topics › remove() in java
remove() in Java - Scaler Topics
April 7, 2024 - The remove method takes a single parameter. obj: The object in the ArrayList is to be removed.
🌐
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
There are actually two methods to remove an existing element from ArrayList, first by using the remove(int index) method, which removes elements with a given index, remember the index starts with zero in ArrayList.
🌐
W3Schools
w3schools.com › JAVA › ref_arraylist_removeif.asp
Java ArrayList removeIf() Method
The removeIf() method removes all elements from this list for which a condition is satisfied.
🌐
TutorialsPoint
tutorialspoint.com › javaexamples › array_removeall.htm
Removing Elements from an ArrayList in Java
The removeAll(Collection<?> c) method in ArrayList removes all elements shared between the ArrayList and the specified collection.
🌐
W3Schools
w3schools.com › java › java_arraylist.asp
Java ArrayList
The difference between a built-in array and an ArrayList in Java, is that the size of an array cannot be modified (if you want to add or remove elements to/from an array, you have to create a new one).
🌐
LeetCode
leetcode.com › problems › find-all-duplicates-in-an-array
Find All Duplicates in an Array - LeetCode
Can you solve this real interview question? Find All Duplicates in an Array - Given an integer array nums of length n where all the integers of nums are in the range [1, n] and each integer appears at most twice, return an array of all the integers that appears twice.
🌐
Reddit
reddit.com › r/learnprogramming › how do i remove an object from an arraylist and delete it in java?
r/learnprogramming on Reddit: How do I remove an object from an arraylist and delete it in java?
March 11, 2021 -

So, basically I want to do a shopping list that you can put the price, quantity, name. I want to implement a button that deletes an object. I have tried doing "int s = objectList.indexOf(myobject); objectList.remove(s); myobject=null;", but it keeps giving me errors. Please help me, if you need any code from my project, I will give it. Btw, the object extends JPanel

🌐
Vultr
docs.vultr.com › java › standard library › java › util › arraylist › removeall()
Java ArrayList removeAll() - Remove Specified Elements
September 27, 2024 - The removeAll() method in Java's ArrayList class is a powerful tool for removing multiple elements from a list simultaneously based on the contents of another collection.