黑马程序员技术交流社区
标题:
ListTest
[打印本页]
作者:
陈冬雪
时间:
2015-8-6 23:06
标题:
ListTest
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());
}
}
}
复制代码
这是今天的
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2