Are these statements completely the same in terms of memory occupation and efficiency in Java?
First:
Object[] array = new Object[100];
int i = 0;
for (; i < array.length; i++){
Object o = array[i];
//do something
}
Second:
Object[] array = new Object[100];
for (int i = 0; i < array.length; i++){
Object o = array[i];
//do something
}
Third:
Object[] array = new Object[100];
for (Object o : array){
//do something
}
In terms of memory occupation and efficiency, yes. However, there are differences. In the first,
iexists (has a scope) beyond the loop; while in the second it does not. In the third case, there is no (direct) way to access the index or to change the array contents at the position of the current object.