I have a list with 13 objects from one class of which a few have the variable "isUsed" set to true and the others to false. How can i remove the objects which have it set to true from the list?
for (Object obj: nameOfTheList) //for each element in the list
{
ClassName cn = (Classname) obj; //cast the object, so you can use the 'isUsed' variable
if (cn.isUsed) getWorld().removeObject(cn); //without 'getWorld' if it is used in a world subclass
//if 'isUsed' isn't public, call the getter method instead
}List<> copy = nameOfTheList
for (Object obj: copy) //for each element in the list
{
ClassName cn = (Classname) obj; //cast the object, so you can use the 'isUsed' variable
if (cn.isUsed) nameOfTheList.remove(cn);
//if 'isUsed' isn't public, call the getter method instead
}List<> copy = nameOfTheList
List copy = new ArrayList(nameOfTheList);
for(Iterator i = nameOfTheList.iterator(); i.hasNext(); ) {
ClassName cn = (Classname) i.next();
if (cn.isUsed) i.remove();
}