best way to remove stuff from a list

say i got an array list and i want to remove all objects with some value. whats the cleanest way to code this?Thanks
[130 byte] By [jinxjinxjinxa] at [2007-11-27 2:43:03]
# 1
to clarify lets say i have and arraylist of Integers and i want to remove all the number 7s from the list. I cant just do this:for(Integer i: list)if i == 7 list.remove(i)because it would be self modifying. so whats the cleanest way to do this?
jinxjinxjinxa at 2007-7-12 3:08:17 > top of Java-index,Java Essentials,New To Java...
# 2

you could try a ListIterator, that allows modification during iteration

ListIterator<Integer> listIterator = list.listIterator();

while (listIterator.hasNext()) {

Integer i = listIterator.next();

if (i == 7)

listIterator.remove();

}

JasonChoya at 2007-7-12 3:08:17 > top of Java-index,Java Essentials,New To Java...