1import java.util.ArrayList;
2public class ListToArray {
3 public static void main(String args[]){
4 ArrayList<String> list = new ArrayList<String>();
5 list.add("Apple");
6 list.add("Orange");
7 list.add("Banana");
8
9 System.out.println("Contents of list ::"+list);
10 String[] myArray = new String[list.size()];
11 list.toArray(myArray);
12
13 for(int i=0; i<myArray.length; i++){
14 System.out.println("Element at the index "+i+" is ::"+myArray[i]);
15 }
16 }
17}