Skip navigation.
Home

Java’s enhanced for loops in JDK 1.5 (Tiger)

Java’s for loops were enhanced in release 1.5 to work more easily with arrays and collections. You often want to perform identical processing on every element of an array. For example, the following method returns the sum of the squares of the members of an array of floats: float sumOfSquares(float[] floats) { float sum = 0; for (int i=0; i