Fill all elements of ArrayList to an Object Array in Java
Description
The following code shows how to fill all elements of ArrayList to an Object Array.
Example
/* w w w . j av a 2s . c om*/
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add("1");
arrayList.add("2");
arrayList.add("3");
arrayList.add("4");
arrayList.add("java2s.com");
Object[] objArray = arrayList.toArray();
for (Object obj : objArray)
System.out.println(obj);
}
}
The code above generates the following result.