I know this is a messy implementation, but I basically have this code (I wrote all of it), and I need to be able to remove a student or instructor from the list when using t
You need to Override equals and hashcode methods for collections to work properly.
@Override
public boolean equals(Object obj) {
if (obj == null)
return false;
if (!(obj instanceof Student))
return false;
Student other = (Student) obj;
return id == null ? false : id.equals(other.id);//Compare Id if null falseF
}
Since you are only using ArrayList there is hashcode method will not be used but it is still good practice to provide it.
@Override
public int hashCode() {
return id == null ? 0 : id.hashCode();
}