I have a arrayList and i want use contains(Thing o) method to check equality of this two object and I override the equals() method in Thing class but this is not work when I call contains method! this is my thing class:
public class Thing{
private int id;
//getter setter
@Override
public boolean equals(Object o) {
if(!(o instanceof Thing))
return false;
if(id == ((Thing)o).getId())
return true;
return false;
}
}
is it necessary to override the hashCode() method too? if yes how to override it?