This piece of Java code shows how to convert a List, in this case an ArrayList, to an Array by calling the method toArray() on the List object.
The toArray() method returns an array of the same type as the array provided as an argument to the method. The argument can be an empty array as in the example below.

 * @author

public class Main {
    public void ListToArray() {
        List<String> carList = new ArrayList<String>();
        String[] carArray = carList.toArray(new String[0]);
        for (String car : carArray) {
     * @param args the command line arguments

    public static void main(String[] args) {
        new Main().ListToArray();

Sandeep Joshi
Mathematics, Technology and Programming are my passion. I am a part of Java Ecosystem and through this blog, I contribute to it. I am here to blog about my interests, views and experiences.
I am on Google+ and Facebook.
I feel proud to be listed as a "National Memory Record Holder" in the Limca Book of Records, 2009 and have attempted for an International Memory record in the Guiness Book of Records. I can remember the value of PI upto 10,000 digits after the decimal (3.1415.....). You can contact me on ; I would like to hear from you :)