Categories
Mastering Development

Removing every other element in an array list

for(int i = 0; i < points.size(); i = i+lines) {
    points.remove(i);
}

The idea here is that a user can either remove every other space or every third space or every fourth space .. And so forth, of an array list by entering an int “line” that will skip the spaces. However, I realize the list gets smaller each time messing with the skip value. How do I account for this? I’m using the ArrayList library from java so don’t have the option of just adding a method in the array list class. Any help would be greatly appreciated.

Leave a Reply

Your email address will not be published. Required fields are marked *