[Bluej-discuss] Exercise 4.31
Craig Johnson
cjohnson at mesabieast.k12.mn.us
Sun Apr 9 23:52:47 BST 2006
I am new to any type of programming so forgive me if my question seems to
be a simple one.
Below is the code for exercise 4.31 and my question relates to the line of
highlighted code.
public ArrayList purge(int month, int year)
{
if(month <1 || month >12){
System.out.println("Invalid Month");
}
ArrayList purged = new ArrayList();
Iterator it = members.iterator();
while(it.hasNext()){
Membership member = (Membership)it.next();
if(member.getMonth() == month && member.getYear() == year){
terminated.add(member);
it.remove();
}
}
return purged;
}
Why can't I substitute it with the following: members.remove(member);
When I do this it will remove the first object of the matching month and
year, but then it will not initialize any futher member local variables.
It won't remove any further matches through iteration.
More information about the bluej-discuss
mailing list