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

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Statements » enhanced for loop 
5.4.1.Enhanced for Loops and array: perform identical processing on every element of an array.
//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.2F2.3F3.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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.