java for each loop came into 1.5 version.
It is the specially designed loop to retrieve elements of arrays and collections.
example 1 :-
Q. print elements of the one-dimensional array?
int [ ] a={1,2,3,4,5};
To prints the elements of the array, we have 2 approaches.
1.old approach (old for loop) :-
for(int i=0 ; i<a.lenght ;i++ )
{
System.out.ptintln(a[i]);
} Output is :
1
2
3
4
5
2. new approach (for each loop):-
for(int a1 :a )
{
System.out.ptintln(a1);
}
Output is :