首页 > 编程语言 > 详细

java List 简单使用

时间:2015-04-22 19:59:09      阅读:223      评论:0      收藏:0      [点我收藏+]

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());//打印信息
		}
	}
}

运行效果

 

 

 

技术分享

java List 简单使用

原文:http://www.cnblogs.com/xuqiulin/p/4448196.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!