Tuesday 20 October 2015

JAVA : HashSet -> Equals and hashCode

JAVA : HashSet -> Equals and hashCode


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

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

WithOut hashCode override:




With hashCode override:


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

No comments:

Post a Comment