The for-each loop will not work for this case. You cannot use a for loop for each loop to initialize an array. Your code:
int[] array = new int[5];
for (int i : array) {
i = 24;
}
will translate something like the following:
int[] array = new int[5];
for (int j = 0; j < array.length; j++) {
int i = array[j];
i = 24;
}
, . , , , , , . . .
, , . for for-each - . "i" ( "int i" ) "array[index]".
Date, , , :
Date[] array = new Date[5];
for (Date d : array) {
d = new Date();
}
:
Date[] array = new Date[5];
for (int i = 0; i < array.length; i++) {
Date d = array[i];
d = new Date();
}
, , . , .
. , .class, jad, . , Sun Java (1.6) :
int array[] = new int[5];
int ai[];
int k = (ai = array).length;
for(int j = 0; j < k; j++)
{
int i = ai[j];
i = 5;
}