编写一个学生类,将学生的姓名,年龄,性别分别保存到hashset,arraylist,hashtable中,并利用迭代器将他们打印出来

解决方案 »

  1.   


    public class Student { private String name; private int age; private String sex; public Student(String name, int age, String sex) {
    this.name = name;
    this.age = age;
    this.sex = sex;
    }
    }public class Test {
    public static void main(String[] args) {
    Student s1 = new Student("C++", 11, "Girl");
    List stuList = new ArrayList();
    Map sMap = new Hashtable();
    Set stuSet = new HashSet();
    stuList.add(s1);
    stuSet.add(s1);
    sMap.put(1, s1);
    }
    }参考之