Can anyone explain to me or point to a tutorial that gives a more detailed explaination to how hashcode() method is used in combonation with a hash collection? Thanks.
Suppose you're looking for a particular book in a library. One approach would be to start with the first book on the first shelf and work your way through the entire library until you find your book. But it would be a lot quicker if you knew which asile contained your book, and you could narrow your search to that area. It would be even quicker if you knew which shelf your book was on.
In effect, hashcode narrows your search to a particular "bucket" or "slot" associated with that hashcode. There might be more than one element in that slot, because unequal objects are not required to return different hashcodes. But if the hashing is good, there shouldn't be too many elements in any one slot. In other words, a book's hashcode would do better to return a shelf number rather than a asile number.
This also illustrates why equal objects must return the same hashcode. If you have multiple copies of the same book, you would expect to find them on the same shelf.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Have the determination of mirror which never fails to reflect in spite of being broken into pieces.<br /> <br />Kiss the hands you cannot bite.<br /> <br />An Optimist is one who starts taking a bath when he accidentally falls into the water.
yeah Marc, That was a great analogy. It sure makes life ( a Lot) easier when these topics are compared to simple real life time situation instead of codes !
Thanks.
The future belongs to those who believe in the beauty of their dreams.Dream BIG!
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.