JAVA: Enhanced For Loop

Enhanced for loop was introduced in JAVA 5 as a simple way to iterate all the elements of a collection.

It is useful when scanning a array instead of using for loop. 

Here we will take a simple example to sum all the elements of an array

    public class EnhancedForLoop {

    public static void main(String[] args) {
       int  arr[]={3,2,4,5};
       int sum=0;
for(int x:arr){

You can also watch my video on YouTube on the same topic. Java:Enhanced For Loop
In Association with In Association with