In the above code the marked line 7 also giving the null, I don't know why it is giving null, because I have defined
both the hashcode and equlas method in the Dog class.
The culprit here is line 52, in which you are changing the name of d1 object. So when you try to retrieve from map the hashcode method will return different value since the name is changed and hence desired object will not be found.