Source Code : Use the for-each for loop to cycle through a collection.

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Use the for-each for loop to cycle through a collection.

     
import java.util.ArrayList;

class ForEachDemo {
  public static void main(String args[]) {
    ArrayList<Integer> vals = new ArrayList<Integer>();

    vals.add(1);
    vals.add(2);
    vals.add(3);
    vals.add(4);
    vals.add(5);

    System.out.print("Original contents of vals: ");
    for (int v : vals)
      System.out.print(v + " ");
    System.out.println();

    int sum = 0;
    for (int v : vals)
      sum += v;

    System.out.println("Sum of values: " + sum);
  }
}

   
    
    
    
  

Thank with us