- package cn.itcast_02;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.List;
- public class ListTest {
- public static void main(String[] args) {
-
- List list = new ArrayList();
-
- Student s1 = new Student("顾里",18);
- Student s2 = new Student("林萧",18);
- Student s3 = new Student("南湘",18);
- Student s4 = new Student("唐宛如",18);
-
- list.add(s1);
- list.add(s2);
- list.add(s3);
- list.add(s4);
-
- //Iterator it = list.iterator();
- //while (it.hasNext()) {
- // Student s = (Student) it.next();
- // System.out.println(s.getName()+"---------"+s.getAge());
- //}
-
- Iterator it = list.iterator();
- while (it.hasNext()) {
- Student s = (Student) it.next();
- System.out.println(s.getName()+"----"+s.getAge());
-
- }
-
- for (int i = 0; i < list.size(); i++) {
- Student s = (Student) list.get(i);
- System.out.println(s.getName()+"********"+s.getAge());
- }
-
- for (int i = 0; i < list.size(); i++) {
- Student s = (Student) list.get(i);
- System.out.println(s.getName()+s.getAge());
- }
-
- }
- }
复制代码
这是今天的 |
|