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

//1.The first way 
		Iterator> it = cla.iterator();
		int count = 1;
		while(it.hasNext()) {
			Iterator itt = it.next().iterator();
			System.out.println(" "+count+" ");
			while(itt.hasNext()) {
				System.out.println(itt.next().getName()+"----------" +itt.next().getAge());
			}
			count++;
		}
		
		System.out.println("---------------------");

//2.The second way 
		for(int i=0 ; i cl: cla) {
			System.out.println("Class:"+cou);
			for(Student sl:cl) {
				System.out.println(sl.getAge()+"---------------"+sl.getName());
			}
		}
		
//		System.out.println(st);
		
	

 

你可能感兴趣的:(java)