source code ArrayList to Array convertion
package collection;
import java.util.ArrayList;
public class ArrayList2Array {
public static void main(String[] args) {
ArrayList a=new ArrayList();
a.add(new Integer(100));
a.add("java");
a.add(new Integer(200));
a.add(new Integer(300));
System.out.println(a); // here ArryList toString method called
// ArrayList to Array by using toArray method
Object o[]=a.toArray();
for(int i=0;i<a.size();i++ )
System.out.println(o[i]);
}
}
output:
[100, java, 200, 300]
100
java
200
300
0 comments:
Post a Comment