#PTAOOP059. 5-9 迭代器遍历列表
5-9 迭代器遍历列表
本站提交说明
此题属于 面向对象程序设计练习。请在练习页填写原题的填空或函数片段并提交;本题独立提交页接收拼接后的完整 Java 程序。
评测使用题面样例与本站补充测试,包含编译、输出及部分成员 API 检查。通过本站测试不代表通过 PTA 隐藏测试。
本题目要求使用迭代器遍历学生列表。
import java.util.*;
/* 这里是 Student 类代码,无需关心
*/
public class Main {
public static void main(String args[]) {
List<Student> list = new ArrayList<Student>();
list.add(new Student("2016001","rose",18));
list.add(new Student("2016002","hunifu",19));
list.add(new Student("2016003","britsh",20));
Iterator<Student> it = ; //创建迭代器
while ( ) { //判断遍历是否结束
Student stu=;//取列表元素
System.out.println(stu);
}
}
}
本站测试模板说明
- 题面省略 Student 类;完整示例补了最小本地实现,其 toString 格式不代表隐藏裁判。