public class Student{
private String name;
private int age;
public Student(String name, int age) {
super();
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
public class Collection01 {
public static void main(String[] args) {
Collection<Student>stu=new ArrayList<Student>();
Student s1=new Student("lily",18);
Student s2=new Student("linda",20);
Student s3=new Student("bob",24);
stu.add(s1);
stu.add(s2);
stu.add(s3);
Iterator<Student> it=stu.iterator();
while(it.hasNext())
{
Student s=it.next();
System.out.println(s.getName()+"\t"+s.getAge());
}
}
}
![](https://img-blog.csdnimg.cn/0f2db88be10f41f7b408bf405fdf12ab.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5a655LiOMDgwMQ==,size_11,color_FFFFFF,t_70,g_se,x_16)