for ( parameter : arrayName) loop body
int[] values = new int[10]; // other statements that load array with data... int total = 0; for (int i = 0; i < values.length; i++) total = total + values[i]; System.out.println("The total is " + total);
int[] values = new int[10]; // other statements that load array with data... int total = 0; for (int number : values) total = total + number; System.out.println("The total is " + total);
typeName... variableName
void doTask(int x, double... values) // LEGAL void doThing(double... values, int size) // ILLEGAL void doThing(double... values, int... numbers) // ILLEGAL
double d1, d2, d3, d4; doTask(5, d1, d2); doTask(5, d1, d2, d3); doTask(5, d1, d2, d3, d4); doTask(5, d1, d2, d3, d4, 3.4, 5.9, 12.4);
void printStats(double... values) { for (double val : values) System.out.print(val + " "); }