can anyone please specify to me what are the advantages of Enhanced for loop and Iterators in java +5 ?
As others said, the enhanced for loop provides cleaner syntax, readable code and less type.
Plus, it avoids the possible 'index out of bound' error scenario too. For example, when you iterate a list manually, you might use the index variable in a wrong way, like:
for(int i=0; i<= list.size(); i++)
which will throw exception. But incase of enhanced for loop, we are leaving the iterating task to the compiler. It completely avoids the error case.