Statement Control Java Tutorial

For-Each Loop can be used to any object that implements the Iterable interface.
This includes all collections defined by the Collections Framework,

import java.util.ArrayList;
 
public class MainClass { 
    
  public static void main(String args[]) { 
    ArrayList list = new ArrayList();
    list.add(10.14);
    list.add(20.22);
    list.add(30.78);
    list.add(40.46);
    double sum = 0.0;
    for(double itr : list)
      sum = sum + itr;
    System.out.println(sum);
  
  } 
}
101.6