Enhanced array for references. : enhanced for loop « Statements « SCJP






public class MainClass {
  public static void main(String[] argv) {
    String[] strings = new String[] { "a", "asdf", "adfadsfa", "a" };
    int totalLength = 0;
    for (String s : strings)
      totalLength += s.length();
    System.out.println(totalLength);

  }
}
14








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