How to use for each loop with Java array?

We can use a collection-based for loop as an alternative to the numerical for loop when processing the values of all the elements in an array.



The syntax of for each loop for an array is as follows.



for(arrayType variableName: array){

  process each variableName



Java array for each loop


public class Main {

  public static void main(String args[]) {

    int days[] = {1, 2, 3,};

    for(int i:days){