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.
ListToArrayTest.java
package test;
import java.io.IOException;
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>();
strList.add("string1");
strList.add("string2");
strList.add("string3");
String[] strArray = (String[]) strList.toArray(new String[0]);
System.out.println(ArrayUtils.toString(strArray));
}
}
Here is the output from ListToArrayTest.
Results
{string1,string2,string3}