For-Each Loop
There is also a “for-each” loop, which is used exclusively to loop through elements in an array (or other data sets):
Syntax
for (type variableName : arrayName) {
// code block to be executed
}
The following example outputs all elements in the cars array, using a “for-each” loop: Continue reading Java For Each Loop