import java.util.ArrayList;
import java.util.List;
class Person {
int age;
public Person(int age) {
this.age = age;
}
}
public class Test{
public static void main(String[] args) {
List<Person> list = new ArrayList<Person>();
list.add(new Person(1));
list.add(new Person(2));
Person[] pro = (Person[]) list.toArray(new Person[list.size()]);
for(int i=0;i<pro.length;i++){
System.out.println(pro.age);
}
}
} |