【发布时间】:2011-10-28 15:37:39
【问题描述】:
我有一个 Personnel 类,我在其中存储所有学生、教授、导师类型的对象...
class Personnel {
ArrayList<Student> activeStudentsList = new ArrayList<Student>();
}
我有一个班级学生
class Student extends Person {
public Student (String studentID, String firstName, String lastName) {
super(firstName, lastName);
this.studentID = studentID;
}
}
现在,在将学生添加到数组列表之前,我想做的是检查他是否已经存在。我正在使用这个:
private boolean isStudentActive(String studentID) {
if (activeStudentsList.contains(studentID)) {
System.out.println("The student " + studentID + " is already on the list.");
return true;
} else
return false;
}
问题是,我的数组列表是ArrayList<Student>,所以我无法搜索特定的字符串(studentID)。我该怎么做呢?如何只搜索列表中每个对象的字符串studentID?
编辑:(有类似activeStudentsList.studentID.contains(studentID) 的东西吗?)
【问题讨论】: