Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ArrayList Tip
#1
When using an ArrayList that accepts integer objects like so,
Code:
ArrayList<Integer> list = new ArrayList<Integer>();
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,
Code:
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(3);
If you wanted to remove the number 2 in the list you would invoke,
Code:
list.remove((Integer) 2);
because if you call the remove method without casting, it will remove the object at index 2. Heres how this happens,
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.
My SMF Modifications:
http://anthony.vibrantvps.com/smf
Reply


Messages In This Thread
ArrayList Tip - by Project Evolution - 01-01-2010, 11:31 AM
RE: ArrayList Tip - by Qkyrie - 01-09-2010, 06:53 PM
RE: ArrayList Tip - by Ⱳąŗɗ - 03-13-2010, 10:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Adding Elements to Array or ArrayList? BleepyEvans 1 1,147 05-19-2017, 03:52 AM
Last Post: Clarencetew24

Forum Jump:


Users browsing this thread: 1 Guest(s)