01-01-2010, 11:31 AM
(This post was last modified: 01-01-2010, 05:57 PM by Project Evolution.)
When using an ArrayList that accepts integer objects like so,
Be sure to call the remove method and cast it with an integral value in the list becasue the ArrayList class has both the remove(integer) and remove(Object).
Basically we have,
If you wanted to remove the number 2 in the list you would invoke,
because if you call the remove method without casting, it will remove the object at index 2. Heres how this happens,
If it removes what is at index 2, it will remove the number 3 because always remember, Arrays start at 0 not 1!
Thanks.
Code:
ArrayList<Integer> list = new ArrayList<Integer>();
Basically we have,
Code:
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(3);
Code:
list.remove((Integer) 2);
Code:
list.remove(2);
If it removes what is at index 2, it will remove the number 3 because always remember, Arrays start at 0 not 1!
Thanks.