0
Java - remove() function for ArrayList<class> (I need help)
how can i remove an element that i had added before in the ArrayList<> I create it like that, public static ArrayList<Product> P = new ArraList<Product>(); and // the method i am using public void removeProduct(Product p) { P.remove(p); // this way , did not solve the problem } // comment BTW, i did the (add method) and it works and everything are fine, i hope someone could help to get the answer and thanks :)
4 Respostas
+ 3
https://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html
In the documentation you will find different remove methods. For example Arraylist.remove(int index) --> removes the value at the index.
+ 3
ahmadaljanabi But you need the index of the element to remove it.
You can not write remove(value) --> write: remove(index of value). And the index of a value is an integer.
For example:
YourList = [A, B, C]
yourList.remove(1) --> remove value/element at index 1
YourList = [A,C]
+ 1
okay thanks
0
I wanna delete a String element there not by integer value, i appreciate your answer, thanks