java三种方法遍历二重嵌套集合

时间:2025-03-19 18:07:36
// first way 
		Iterator<ArrayList<Student>> it = ();
		int count = 1;
		while(()) {
			Iterator<Student> itt = ().iterator();
			(" "+count+" ");
			while(()) {
				(().getName()+"----------" +().getAge());
			}
			count++;
		}
		
		("---------------------");

// second way 
		for(int i=0 ; i<() ; i++) {
			("Class"+(i+1));
			for(int j=0 ; j<(i).size() ; j++) {
				Student s = (i).get(j);
				(()+"------------"+());
			}
		}
		
// third way 
		int cou = 1;
		for(ArrayList<Student> cl: cla) {
			("Class:"+cou);
			for(Student sl:cl) {
				(()+"---------------"+());
			}
		}
		
//		(st);