Java--遍历嵌套list的三种方法

//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             System.out.println("Class"+(i+1));
            for(int j=0 ; j                 Student s = cla.get(i).get(j);
                System.out.println(s.getName()+"------------"+s.getAge());
            }
        }
        
//3.The third way 
        int cou = 1;
        for(ArrayList cl: cla) {
            System.out.println("Class:"+cou);
            for(Student sl:cl) {
                System.out.println(sl.getAge()+"---------------"+sl.getName());
            }
        }
        
//        System.out.println(st);

你可能感兴趣的:(Java--遍历嵌套list的三种方法)