using for each loop in java

Using For Each in Java


  • How to use For Each in Java?
  • How to use advance for in Java?
  • How to use advance for loop in Java Programming Language?
  • Types of For loop in Java


Source Code:

[sourcecode lang=”Java”]

class ForEachExample
public static void main(String args[])
//declaring an array
int a[]={1,2,3,4,5,6};

// Old way
System.out.println("Old way");
for(int i=0; i<a.length;i++)

//New way: for-each loop
System.out.println("For each");
for(int i:a)