for (Cat cat:cats)
{
pets.remove(cat);
}
Above is what I used to solve the remove method step. Can someone please explain why I did not need an iterator for this?
Solution passed
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Michael Brimage
22 March 2020, 20:35
Anthony Cheers!!!
thanks much
0
Anthony Chalk
20 March 2020, 09:31
Because you're iterating over one Set (cats) and removing elements from the other Set (pets).
If you wanted to remove items from the same Set that you were iterating over, you would indeed need an Iterator (or you could make a copy of the Set)
+2