| Author |
hashCode( )
|
Maureen Charlton
Ranch Hand
Joined: Oct 04, 2004
Posts: 218
|
|
I have the following output: JOHN DOE : Java Calculated hash=4 for JOHN DOE students[hash]: JOHN DOE : Java students hashCode value = 21990827 Could someone explain why I got the hashCode value = 21990827 and NOT 4? (4 is what I was expecting? Do I need to have a toString( ) method? Similar to when I wish to have something more meaningful when printing out the contents of an array? Thanking you in advance!
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
|
|
You need to override hashCode() in Student. If you wanted the hashCode() for a Student object to be the same as the hashCode() for the Student's name, then you could write
|
[Jess in Action][AskingGoodQuestions]
|
 |
 |
|
|
subject: hashCode( )
|
|
|