posted 13 years ago
I re-formatted your code, and put in code tags. with over 100 posts, you've been around long enough to know how to do that yourself.
to your code...think about it. you set the size variable to 3.
you start iterating through, and remove an element. the lists size is now 2, but your size variable is still 3.
you move to the next element, and remove it. the list now has a size of 1. your counter is now set to 2, which is still less than your size variable, so we loop again.
you now say "remove the element at position 2", but the list only has one element in it - hence the out of bounds exception.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors