Source Code : Convert an ArrayList into an array.

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

Convert an ArrayList into an array.

      
import java.util.ArrayList;

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

    al.add(1);
    al.add(2);
    al.add(3);
    al.add(4);

    System.out.println("Contents of al: " + al);

    Integer ia[] = new Integer[al.size()];
    ia = al.toArray(ia);

    int sum = 0;

    for (int i : ia)
      sum += i;

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

   
    
    
    
    
  

Thank with us