I don't think it really matter what implementation of a hash one uses. The focus of the article was on the hashCode method. If you're interested in which hash implementation to use, refer to the link cited at the beginning of that article.
1. There is very small error with Corey's third example (hold true to Rule #1 but not to Rule #2). The output does not correspond to the program. The actual output is:
1 2 3 4 6 6 7 8 9 10 Elapsed Time: 0 ms
Note the two 6s. This is because the keys array holds two objects that are created using the same values (MyObject(11,5)).
2. I was initially a bit confused by example 3 when I simply looked at the output. I expected there only to be one "10" string object in the hash table and the output appeared to show ten "10"s! I took another look at the code and I realized that the ten "10"s is what was expected from the actual code since the code get the elements from hash table using the 10 keys in the keys array.
It can be educational to inspect what keys are actually saved by the hash table.
For those readers wondering how to do this, you can do this with the following code:
When you run this, the output is:
The keySet in the hash table: [[11,0], [11,1], [11,2], [11,3], [11,5], [11,6], [11,7], [11,8], [11,9]] 1 2 3 4 6 7 8 9 10
Then, when you fix hashCode to conform to the rules (e.g. return a), the output is:
The keySet in the hash table: [[11,0]] 10
Cheers! [ October 23, 2004: Message edited by: Brian S. Hayes ]