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
2010-10-28 11:33:53
+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
2010-10-28 11:34:52
Thank you for your help
Alex
2010-10-28 12:30:30
A:
List <String> list = ...
String[] array = new String[list.size()];
int i=0;
for(String s: list){
array[i++] = s;
}
HZhang
2010-10-28 12:58:15