import java.util.*;
class CollectionNest
{
public static void main(String[] args)
{
//开发系
ArrayList<ArrayList<Student>> serie = new ArrayList<ArrayList<Student>>();
//ui班级
ArrayList<Student> uiclass = new ArrayList<Student>();
Student s1 = new Student("zhangsan",21);
Student s2 = new Student("lisi",21);
Student s3 = new Student("wangwu",24);
uiclass.add(s1);
uiclass.add(s2);
uiclass.add(s3);
//java班级
ArrayList<Student> javaclass = new ArrayList<Student>();
Student ss1 = new Student("zhaoliu",24);
javaclass.add(ss1);
//加班级到开发系
serie.add(uiclass);
serie.add(javaclass);
//遍历
for(ArrayList<Student> al:serie)
{
for(Student s:al)
{
System.out.println(s.getName()+"---"+s.getAge());
}
}
}
}
class Student
{
private int age;
private String name;
public Student()
{
}
public Student(String name,int age)
{
this.name = name;
this.age = age;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
} |
|