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). Answer from captainAwesomePants on reddit.com
๐ŸŒ
Kotlin
kotlinlang.org โ€บ docs โ€บ whatsnew23.html
What's new in Kotlin 2.3.0 | Kotlin Documentation
4 weeks ago - The new explicit syntax simplifies the common backing properties pattern where a property's internal type is different from its exposed API type. For example, you might use an ArrayList while exposing it as a read-only List or a MutableList.
๐ŸŒ
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

Discussions

java - How to delete specific element from array list - Stack Overflow
Im trying but its not good. Here is all code: //creating passener object Passenger passenger1 = new Passenger(1, "Stefan", "Jankovic", "stefan@gmail.com", 300... More on stackoverflow.com
๐ŸŒ stackoverflow.com
java - Circular Linked List Implementation - Code Review Stack Exchange
I am currently taking a data structures course at my university right now. I've recently learned about linked lists. Here is my attempt at creating a doubly circular linked list in Java. Is there More on codereview.stackexchange.com
๐ŸŒ codereview.stackexchange.com
2 weeks ago
(Java) Can't remove element from List/ArrayList, always gives NullPointerException or ConcurrentModificationException.
You add every line to the list, but the last line of the file will always return null. You correctly end the loop at that point, but you still add null to the list. That's what is giving those nullpointer exceptions More on reddit.com
๐ŸŒ r/AskProgramming
6
1
October 27, 2019
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
๐ŸŒ
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. See More Examples below for an example. ... T refers to the data type of items in the list. 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); } }
๐ŸŒ
JavaGoal
javagoal.com โ€บ home โ€บ how to remove element from arraylist java
remove element from ArrayList java and remove(), removeIf() - JavaGoal
July 26, 2020 - Where, Object represents the type of class in ArrayList . obj is the element which you want to remove from the ArrayList . return type: Its return type is boolean. It can return either true or false. If specified obj presents in ArrayList then it returns true after removal of obj otherwise it returns false. import java.util.ArrayList; public class ArrayListExample { public static void main(String[] args) { ArrayList<String> listOfNames = new ArrayList<String>(); listOfNames.add("JAVA"); listOfNames.add("GOAL"); listOfNames.add("Learning"); listOfNames.add("GOAL"); System.out.println("Before re
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java collections โ€บ removing elements from java collections
Removing Elements from Java Collections | Baeldung
January 8, 2024 - Collection<String> names = new ArrayList<>(); names.add("John"); names.add("Ana"); names.add("Mary"); names.add("Anthony"); names.add("Mark"); Javaโ€™s Iterator enables us to both walk and remove every individual element within a Collection.
๐ŸŒ
CODEDOST
codedost.com โ€บ home โ€บ java โ€บ collections in java โ€บ remove element from a specific index in arraylist in java
Remove element from a specific index in ArrayList in JAVA | CODEDOST
July 27, 2021 - remove an element from a specific index in ArrayList in JAVA, we need to use the remove(int index) method of Java.util.ArrayList class. remove(int index) method will remove the specified element from the Arraylist
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 627559 โ€บ java โ€บ remove-item-Arraylist-looping
How to remove a item from Arraylist without looping it (Java in General forum at Coderanch)
January 25, 2014 - i have a Array-list which contain list of names.I need to remove one name.I can do this using for loop and find the index of element and delete it.But i need to delete it without looping.Is there any method to delete element by name? or can i use any other Data Structure in Java for this issue? ... You don't need to loop. There's already an API http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html#remove(java.lang.Object) ... Thanks Jaikiran. ... sam liyanage wrote:But i need to delete it without looping. I don't know where that requirement came from; let me point out that the ArrayList.remove(Object) very likely uses looping to achieve its goal.
Find elsewhere
๐ŸŒ
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
For example, a call to remove("two") will remove the second element from ArrayList. Though you should remember to use the Iterator or ListIterator remove() method to delete elements while iterating, using ArrayList's remove methods, in that case, will throw ConcurrentModificationException in Java.
๐ŸŒ
coderolls
coderolls.com โ€บ remove-element-from-arraylist
How To Remove An Element From An ArrayList? - Coderolls
December 2, 2021 - remove(Object o) - we can remove the specified object from the ArrayList ยท remove(int index) - We can remove an element at the position (index) specified ยท The example Java programs given in the above tutorial can be found at this GitHub Repository.
๐ŸŒ
Quora
quora.com โ€บ What-does-the-remove-of-the-arraylist-element-mean
What does the remove of the arraylist element mean? - Quora
Answer (1 of 2): Yep, when an item is removed from an ArrayList, all items after it will move forward to fill the space. If you remove element four (which is what list.remove(4); does), all the items after item number 5 (lists are zero indexed) ...
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ ref_arraylist_removeall.asp
Java ArrayList removeAll() Method
import java.util.ArrayList; public ... cars.removeAll(cars); System.out.println(cars); } } ... The removeAll() method removes all items from a list which belong to a specified collection....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ remove-all-occurrences-of-an-element-from-array-in-java
Remove all Occurrences of an Element from Array in Java - GeeksforGeeks
July 11, 2025 - Illustration: Using the ArrayList to remove all occurrences of an element from an array. ... // Java program remove all occurrences // of an element from Array using ArrayList import java.util.ArrayList; import java.util.Arrays; import java.util.List; // Driver Class public class Geeks { // Main Method public static void main(String[] args) { Integer[] a = { 3, 9, 2, 3, 1, 7, 2, 3, 5 }; // Element to be removed Integer k = 3; // Convert array to ArrayList List<Integer> l = new ArrayList<>(Arrays.asList(a)); // Remove all occurrences of the element l.removeAll(Arrays.asList(k)); // Convert ArrayList back to array Integer[] newArr = l.toArray(new Integer[0]); // Print the result System.out.println(Arrays.toString(newArr)); } }
๐ŸŒ
CodeChef
codechef.com โ€บ practice โ€บ arrays
Practice Arrays
Solve Arrays coding problems to start learning data structures and algorithms. This curated set of 23 standard Arrays questions will give you the confidence to solve interview questions.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ java-remove-array-elements
How to Remove Array Elements in Java | DigitalOcean
May 2, 2025 - In this tutorial, we explored various methods for removing elements from arrays in Java, including using for loops, System.arraycopy(), and converting to an ArrayList. We also highlighted the advantages of using ArrayLists for frequent element deletion or addition due to their dynamic nature and built-in functions.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ remove-element-arraylist-java
How to remove an element from ArrayList in Java? - GeeksforGeeks
July 23, 2025 - It is a default method as soon as we do use any method over data structure it is basically operating over indexes only so whenever we do use remove() method we are basically removing elements from indices from an ArrayList. ArrayList class provides two overloaded remove() methods. remove(int index): Accepts the index of the object to be removed ยท remove(Object obj): Accepts the object to be removed ยท Let us figure out with the help of examples been provided below as follows: ... // Java program to Remove Elements from ArrayList // Using remove() method by indices // Importing required classe
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ home โ€บ java/util โ€บ java arraylist remove object
Java ArrayList Remove Object
September 1, 2008 - The java.util.ArrayList.remove(Object) method 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.
๐ŸŒ
Vultr
docs.vultr.com โ€บ java โ€บ standard-library โ€บ java โ€บ util โ€บ ArrayList โ€บ removeIf
Java ArrayList removeIf() - Filter Elements Conditionally | Vultr Docs
November 13, 2024 - The removeIf() method in Java's ArrayList class offers a straightforward way to remove elements from a list based on a condition specified via a lambda expression or predicate.