What data structure should I use to best implement it? Since I will change the property of Student objects in set student (thereby changing the hash codes), should I use an ArrayList instead?
If the hash codes for given elements may change, you should NOT use a HashSet . (If you do this, the data structure will break and the elements in the set may disappear.)
But I doubt that you should use ArrayList too, because if hashcode() sensitive to changes in the object, most likely there will be equals(Object) . This means that contains(...) and similar methods cannot find objects.
I think you should use the Map type and use the "student ID" as the key.
(You can also override hashcode and equals so that equality means that two objects have the same identifier, but this makes equals(Object) useless for other purposes.)
source share