Java: For each loop

This entry is part 11 of 54 in the series Learn Java

The for each loop gives an easy way to iterate through arrays.

On each iteration the next element in the array is assigned to the specified variable, and the loop continues to execute until it has gone through the entire array.

package javaapplication9;

public class JavaApplication9 {

    public static void main(String[] args) {

        int[] array = {1, 2, 3, 4, 5};
        for (int element : array) {


Series Navigation<< Java: Array
Java: Array size >>

Leave a comment

Leave a Reply