日期:2014-05-20 浏览次数:20617 次
public class People { private int age; public int getAge() { return age; } public void setAge(int age) { this.age = age; } }
public class Test { public static void main(String args[]) { List<People> list = new ArrayList<People>(); List<People> list2 = new ArrayList<People>(); People people1 = null; for (int i = 0; i < 5; i++) { people1 = new People(); people1.setAge(i); list.add(people1); } People people2 = null; for(int j = 0;j < list.size();j++){ people2 = list.get(j); people2.setAge(j+10); list2.add(people2); } } }
public class Test { public static void main(String args[]) { List<People> list = new ArrayList<People>(); List<People> list2 = new ArrayList<People>(); People people1 = null; for (int i = 0; i < 5; i++) { people1 = new People(); people1.setAge(i); list.add(people1); } for(int j = 0;j < list.size();j++){ People people2 = list.get(j); people2.setAge(j+10); list2.add(people2); } } }