黑马程序员技术交流社区
标题:
我的作业2
[打印本页]
作者:
lvwangxiao
时间:
2016-3-16 22:40
标题:
我的作业2
public class Student {
private String name;
private int age;
public Student(){}
public Student(String name , int age){
this.name = name;
this.age = age;
}
//重写toString方法
public String toString(){
return name+" " + age;
}
//=============GS===============================================
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
mport java.util.ArrayList;
import java.util.Iterator;
public class Test {
public static void main(String[] args){
ArrayList<Student> student = new ArrayList<Student>();
Student s1 = new Student("xiaoming",20);
Student s2 = new Student("xiaohong",20);
student.add(s1);
student.add(s2);
//返回迭代器
Iterator<Student> iterator = student.iterator();
//调用hasNext与next完成集合迭代
while(iterator.hasNext()){
Student s = iterator.next();
System.out.println(s);
}
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2