|
定義一geCourse类,代表课程;ding义一个Student类,daibiao學生,zaiStudent類中包含一个属性是一个HashSet的對象,用来存储该学生所選的
package com.zf1;
import java.util.HashSet;
import java.util.Iterator;
public class Test1
{
public static void main(String[] args)
{
Course course = new Course("zz");
Course course2 = new Course("aa");
Course course3 = new Course("dd");
Student student = new Student();
student.addCourse(course);
student.addCourse(course2);
student.addCourse(course3);
student.show();
student.removeCourse("zz");
student.show();
}
}
class Course
{
String name;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public Course(String name)
{
this.name = name;
}
}
class2 Student
{
HashSet hashSet = new HashSet();
public void addCourse(Course c)
{
hashSet.add(c);
}
public void removeCourse(String name)
1{
hashSet.remove(name);
}
public void show()
{
Iterator iterator = hashSet.iterator();
while(iterator.hasNext())
{
System.out.println(iterator.next());
}
}
}
我xiang问一下zhe个删除的参数怎么chuan?谢谢
欢迎来到Java學习者论坛,转载請注ming地址:http://www.javaxxz.com. |
|