A for-each loop is an enhanced for loop. It is used to iterate over arrays and collections. This feature was added to Java to make the access and retrieval of elements of arrays and collections faster. The syntax of a for-each loop is as follows:
for(type itrvar: collection)
{
}
where, itrvar is the variable that iterates through the elements of the collection.
Responses to “What is the for-each loop?”