package text;
import java.util.ArrayList;
import java.util.Collection;
public class StudentText {
public static void main(String[] args) {
//创建集合对象
Collection c = new ArrayList();
//创建学生对象
Student s1 = new Student("林自如",15);
Student s2 = new Student("王自健",36);
Student s3 = new Student("林美嘉",18);
//并添加元素到集合
c.add(s1);
c.add(s2);
c.add(s3);
//把集合转成数组
Object[] objs = c.toArray();
//遍历数组
for(int x=0;x<objs.length;x++) {
Student s =(Student)objs[x];
System.out.println(s.getName() +"----"+s.getAge());
}
}
}
import java.util.ArrayList;
import java.util.Collection;
public class StudentText {
public static void main(String[] args) {
//创建集合对象
Collection c = new ArrayList();
//创建学生对象
Student s1 = new Student("林自如",15);
Student s2 = new Student("王自健",36);
Student s3 = new Student("林美嘉",18);
//并添加元素到集合
c.add(s1);
c.add(s2);
c.add(s3);
//把集合转成数组
Object[] objs = c.toArray();
//遍历数组
for(int x=0;x<objs.length;x++) {
Student s =(Student)objs[x];
System.out.println(s.getName() +"----"+s.getAge());
}
}
}