How do I convert a list to an array?
Author: Deron Eriksson
Description: This Java example shows how to convert a list to an array.
Tutorial created using: Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 2.0 (Eclipse 3.3.0)

Converted a list to an array can be accomplished by calling the toArray() method of the list with a parameter indicating the type of array to create. The ListToArrayTest class takes a list of strings and gets an array of strings from this list.

package test;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.ArrayUtils;

public class ListToArrayTest {

	public static void main(String[] args) throws IOException {

		List<String> strList = new ArrayList<String>();

		String[] strArray = (String[]) strList.toArray(new String[0]);



Here is the output from ListToArrayTest.