Edit: Thank you for all your prompt replies. Now I see the assignment won\'t work. From another thread I read that iterator in Java is much less powerful than iterator in C+
It's valid, but it won't do what you want it to do. You'll still have only one iterator, and the outer loop will terminate after the inner one has terminated for the first time.
Java iterators cannot be copied meaningfully. You'll have to use a simple for loop that increments indexes.