标签:
Student类
class Student{ String name; String pwd; public Student(){} public Student(String name, String pwd){ this.name = name; this.pwd = pwd; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPwd() { return pwd; } public void setPwd(String pwd) { this.pwd = pwd; } }
TestList类
public class TestList { public static void main(String[] args) { List list = new ArrayList();//创建List对象 for(int i = 0; i < 4; ++i){//向list对象中添加stu元素 Student stu = new Student("小昆虫"+i, "100"+i); list.add(stu); } Iterator it = list.iterator();//使用迭代器访问list while(it.hasNext()){//判断迭代器是否在链表末尾 Student stu = (Student) it.next();//访问当前元素 System.out.println(stu.getName()+‘\t‘+stu.getPwd());//打印信息 } } }
运行效果
标签:
原文地址:http://www.cnblogs.com/xuqiulin/p/4448196.html