For each looplenhanced for loop): This loop is introduced in java 1.
5 version and it designed
for accessing the elements from arrays(collection). It is also called as enhanced for loop.
Syntax:
for(declaration : arrayName)
statements;
The declaration of avariable in for each loop must be same as that of the type of elements
available in the array. In for each loop, the statements will be executed one time for each element
available in the array and therefore called for each loop.
Program 13:
class ArrayDemo {
public staticvoid main(Stringl] args) {
int[] arr;
arr =new int[5];
[Link](arr[0]);
[Link](arr[1);
[Link](arr[2]);
[Link](arr[3));
[Link](arr[4);
arr[0] = 11;
arr[1]=22;
arr[2]=33;
arr[3] =44;
arr[4] = 55;
for(int i-0; [Link] ;it+) {
[Link](arr[i)):
for(int x: arr) {
[Link](x)