I have a problem with hashMap. More specific with containsKey. I want to check if a object exists in my hash. The problem is when I call this method with 2 different objects containing the same exact data, that should have same hashCode.
Person pers1,pers2;
pers1=new Person("EU",22);
pers2=new Person("EU",22);
public int hashCode(){ //From Person Class
return this.getName().hashCode()+age;
}
After inserting the pers1 key in my hash and calling " hash.containsKey(pers1);" returns true but"hash.containsKey(pers2)" returns false. Why and how could I fix this issue?
Thank you!