Question: how iterator works in java?
Answer: Obtain an iterator to the start of the collection by calling the collection's iterator( ) method.
Set up a loop that makes a call to hasNext( ). Have the loop iterate as long as hasNext( ) returns true.
Within the loop, obtain each element by calling next( ).