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 OverflowHow does an ArrayList remove an element from an array?
How do I remove an object from an arraylist and delete it in java?
Is it as simple as creating another array and moving all of the elements except the one to be deleted over?
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)));
If it is just the ambiguity with the remove() method in Integer ArrayList is bothering you, you can extend the ArrayList to implement your own :
public class MyIntArrayList extends ArrayList<Integer> {
boolean removeByObject(Integer intObj) {
return super.remove(intObj);
}
Integer removeByIndex(int index) {
return super.remove(index);
}
}
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