日期:2014-05-20 浏览次数:20924 次
import java.util.ArrayList; import java.util.Iterator; import java.util.List; class Student{ private Boolean sex; private int age; private String name; public Boolean getSex() { return sex; } public void setSex(Boolean sex) { this.sex = sex; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } } public class listTest { /** * @param args */ public static void main(String[] args) { List al = new ArrayList(); Student std = new Student(); std.setAge(10); std.setName("zhangsan"); std.setSex(true); Student std1 = new Student(); std.setAge(20); std.setName("lishi"); std.setSex(true); Student std2 = new Student(); std.setAge(19); std.setName("wangwu"); std.setSex(true); al.add(std); al.add(std1); al.add(std2); for(Iterator ite = al.iterator();ite.hasNext();){ Student s = (Student)ite.next(); System.out.println(s.getAge()+"--"+s.getName()+"--"+s.getSex()); } } }