Here is a Java Program to Copy all elements of Java ArrayList to an Object Array Example
Output of Above Java Program
ArrayList elements are copied into an Array. Now Array Contains..
1
2
3
4
5
import java.util.ArrayList; class CopyElementsOfArrayListToArrayExample { public static void main(String[] args) { ArrayList arrayList = new ArrayList(); arrayList.add("1"); arrayList.add("2"); arrayList.add("3"); arrayList.add("4"); arrayList.add("5"); Object[] objArray = arrayList.toArray(); System.out.println("ArrayList elements are copied into an Array. Now Array Contains.."); for(int index=0; index < objArray.length ; index++) System.out.println(objArray[index]); } }
Output of Above Java Program
ArrayList elements are copied into an Array. Now Array Contains..
1
2
3
4
5