题目内容
本程序利用List集合实现Student对象的存储与管理。请在阅读程序基础上完成填空(共5个空)。import java.util.*;class Student{private int id;private String name;private int age;public Student(int id,String name,int age){this.id=id;this.name=name;this.age=age;}// 此处为各属性的setter和getter方法(略)...public String toString(){return name + ":" + id + ":" + age;// 注:字符串中的冒号为英文符号}}public class TestList {public static void main(String[] args) {//声明List对象,创建LinkedList对象List list = (1);Student stu1 = new Student(20001, "蔡长锦", 20);Student stu2 = new Student(20006, "皮慧芳", 21);Student stu3 = new Student(20003, "董凯莉", 19);Student stu4 = new Student(20008, "孟卫东", 26);Student stu5 = new Student(20009, "齐贵田", 22);list.add(stu1);list.add(stu2);list.add(stu3);list.add(stu4);list.add(stu5);// 使用普通for循环遍历所有的Student对象for (int i = 0; i < list.size(); i++) {System.out.println((2) );}// 下面的语句删除学号为20006的学生(3) ;// 使用迭代器遍历所有的Student对象Iterator iter = (4) ;while((5) ){System.out.println(iter.next());}}}
查看答案
搜索结果不匹配?点我反馈
更多问题