Saturday, July 26, 2008

Java: Cast ArrayList to Array

import java.util.ArrayList;
public class CastAryListToArray {
public static void main(String arg[]){
//How to cast ArrayList to Array
//The following code will store arraylist value into array:
ArrayList al = new ArrayList();
al.add("a");
al.add("b");
al.add("c");
String XAxisValue[] = new String[al.size()];
al.toArray(XAxisValue);

for(int i=0;i<XAxisValue.length;i++){
   System.out.println("XAxisValue["+i+"] = " + XAxisValue[i]);
}
}
}

No comments:


Since 26 July 2008: