Try to understand why we need hashCode method and why we need equals method and how they are interlinked. Try to understand how equals and hashcode method are used with maps. Then you will be able to understand difference and similarities between two methods.
SCENARIO: ...we want to sort out a couple of balls- so it's easy to find them later. some red, some blue, some green, etc...
20 balls in all (labeled 1 - 20, each ball has a unique number) 5 greens (1 - 5) 5 reds (6 - 10) 5 blues (11 - 15) 5 yellows (16 - 20)
...what we do is pick a ball from our pile- if it's red, it goes in our red bucket, blues in blue bucket, etc...
...if the two of us have that agreement (ie. me sorting the balls into their relative colored buckets and you coming for a ball later), then you can come later on (after i have left) and find it an easy task to find that red ball (say marked number 9) that you are looking for.
HASHCODE the colored buckets- quick way for you to know where the ball you are looking for is.
EQUALS that unique number (remember 1 - 20) that identifies the exact ball you are looking for.
CONCLUSSION if the methods are implemented properly (yes -some wack programmers don't implement them properly - be sure you will see this on the exam) then if we are looking for the no. 9 ball (from our earlier chart), the ball must be red and it must be in the red bucket.
a no. 6 - 10 ball is red but
a red ball is not necessarily a no. 9 ball-> figure that out :roll: