Tuesday 20 October 2015

JAVA : HashMap -> Equals and HashCode

JAVA : HashMap -> Equals and HashCode


1. In HashMap (key, value) -> if we are adding string or int as key then no need of equals and hascode override, If we are using object (Eg : Employee) as a key then we need to override equals and hashcode method.

Below screen shot, since we are going to use Employee object as a key in HashMap, If we dont override hashCode method how HashMap behaves.

WithOut hashCode override:




With hashCode override:

Ref : https://www.youtube.com/watch?v=IwUwIrz9Ge8

No comments:

Post a Comment