0
How Arrays work with Foreach, when they don't have Iterable implemented?
arrays Iterable
2 ответов
+ 4
int arr[]={1,2,3,4,5};
for(int i:arr){
System.out.println(i);
}
It just stores all elements one by one replacing old elements for every new iteration of array or a collection in the declared variable,like in abv example it stores 1st element of array in "i" and then u do whatever u want with that data,and it keeps going till the last element.
How it works you say..it might have an iterative method or sortof methods internally,which gets invoked when you use foreach loop..Not sure though :0
0
for each loop automatically incremented. You don't need to know the size of an array. this is the magic of for each loop.