Java Program to convert ArrayList to Array

Program

import java.util.List;
import java.util.ArrayList;
public class ArrayListToArrayDemo
{
    public static void main(String[] args)
    {
        List<String> countryList = new ArrayList<String>();
        countryList.add("India");
        countryList.add("Australia");
        countryList.add("France");
        countryList.add("Germany");
        System.out.println("From ArrayList:");
        System.out.println(countryList);
        String[] countryArray = countryList.toArray(new String[countryList.size()]);
        System.out.println("From array:");
        for(int i = 0; i < countryArray.length; i++)
            System.out.println(countryArray[i]);
    }
}

Output

From ArrayList:
[India, Australia, France, Germany]
From array:
India
Australia
France
Germany