views:

78

answers:

3

How t convert string array list to string array in java ?

+2  A: 

By using the toArray method:

http://download.oracle.com/javase/1.5.0/docs/api/java/util/ArrayList.html#toArray()

RoToRa
+10  A: 
List<String> list = ..;
String[] array = list.toArray(new String[list.size()]);

The toArray() method without passing any argument returns Object[]. So you have to pass an array as an argument, which will be filled with the data from the list, and returned. You can pass an empty array as well, but you can also pass an array with the desired size.

Bozho
Thank you for your help
Alex
A: 
List <String> list = ...
String[] array = new String[list.size()];
int i=0;
for(String s: list){
  array[i++] = s;
}
HZhang