arrays Various ways of accessing arrays Iterating an Array with a For Each loop in Java


Example

int [] arr = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
for(int value : arr) {
    System.out.print(value);
    System.out.print("\n");
}

*Note that the Java foreach is just a for loop with different syntax. Some languages do this and some such as C# use foreach.