Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Foreach Loop in Java:-

It is modified form of  for loop which is basically used in Array and Collection Object.

foreach loop is used to display the elements of array.

for(datatype o:arrayname)
{
    System.out.println(o);
}

int arr[] = {12,23,34,11,56};

for(int x:arr)
{
     System.out.println(x);
}

int arr[][] = {{12,2},{11,2}}

for(int a[]:arr)
{
    for(int b:a)
    {
         System.out.print(b);
     }
     System.out.println();
}


Program Explanation of For-Each Loop in JAVA:-

class ObjectArr
{
     
 public static void main(String args[])
  {
     Object arr[] = {"C",12.34,true,'a'};
     for(Object o:arr)
     {
           System.out.println(o);
             
     }
 

  }




}





Post a Comment

POST Answer of Questions and ASK to Doubt

Previous Post Next Post