Enhanced for Loops and array: perform identical processing on every element of an array. : enhanced for loop « Statements « SCJP






//for (type variable_name:array)
//The type must be compatible with the array type. 



public class MainClass {
  public static void main(String[] argv) {
    float[] floats = new float[] { 1.2F, 2.3F, 3.4F };
    float sum = 0;
    for (float f : floats)
      sum += f;
    System.out.println(sum);
  }
}
6.9








5.4.enhanced for loop
5.4.1.Enhanced for Loops and array: perform identical processing on every element of an array.
5.4.2.Enhanced array for references.
5.4.3.Legal and illegal enhanced for declarations