1> If there wasn't an exception when using the for loop than it was a coincidence of timing.
2> When I ran the tests it took 3 tries to get an error on the iterator and 5 tries to get the same error using the for loop.
3>The for loop uses an iterator behind the scenes. It is not synchronized. If you want to prevent the concurrent modification exceptions you need to use a synchronized block.
3> How do I know? Because Sun told me so.. "... you don't have to declare the iterator, ... (The compiler does this for you behind your back...)". I could probably come up and check the binary to be sure, but at the moment I trust Sun and take their word for it.
Originally posted by junchen liu:
the link which you gave me, doesn't say anything about "for loop uses an iterator behind the scenes". does it?