A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区


                Collection col = new ArrayList();
                col.add(new Student("123",20));
                col.add(new Student("acb",22));
                col.add(new Student("!@#",19));

                //1. 集合方法iterator()获取迭代器对象
                Iterator it = col.iterator();
                //2. 循环调用hasNext方法,判断集合中有没有下一个元素
                while(it.hasNext()){
                        Student stu =(Student) it.next();
                        System.out.println(stu.getName()+".."+stu.getAge());
                }

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马