集合的嵌套遍历
获取10个1-20之间的随机数,要求不能重复
键盘录入多个数据,以0结束,要求在控制台输出这多个数据的最大值。
public static void main(String[] args){
//创建大集合
ArrayList> bigArrayList = new ArrayList>();
//创建第一个班级的学生集合
ArrayList firstArrayList = new ArrayList();
//创建学生
Student s1 = new Student("学生1",20);
Student s2 = new Student("学生1",20);
Student s3 = new Student("学生1",20);
Student s4 = new Student("学生1",20);
Student s5 = new Student("学生1",20);
//学生进班
firstArrayList.add(s1);
firstArrayList.add(s2);
firstArrayList.add(s3);
firstArrayList.add(s4);
firstArrayList.add(s5);
//把第一个班级存储到学生系统中
bigArrayList.add(firstArrayList);
//创建第二个班级的学生集合
ArrayList secondArrayList = new ArrayList();
//创建学生
Student s6 = new Student("学生2",20);
Student s7 = new Student("学生2",20);
Student s8 = new Student("学生2",20);
Student s9 = new Student("学生2",20);
Student s10 = new Student("学生2",20);
//学生进班
secondArrayList.add(s6);
secondArrayList.add(s7);
secondArrayList.add(s8);
secondArrayList.add(s9);
secondArrayList.add(s10);
//把第二个班级存储到学生系统中
bigArrayList.add(secondArrayList);
//创建第三个班级的学生集合
ArrayList thirdArrayList = new ArrayList();
//创建学生
Student s11 = new Student("学生3",20);
Student s12= new Student("学生3",20);
Student s13 = new Student("学生3",20);
Student s14 = new Student("学生3",20);
Student s15 = new Student("学生3",20);
//学生进班
thirdArrayList.add(s11);
thirdArrayList.add(s12);
thirdArrayList.add(s13);
thirdArrayList.add(s14);
thirdArrayList.add(s15);
//把第三个班级存储到学生系统中
bigArrayList.add(thirdArrayList);
//遍历集合
for(ArrayListarray:bigArrayList){
for(Student s:array){
System.out.println(s.getName()+"----"+s.getAge());
}
}
}