Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Find array index from hashCode()

807588May 8 2009 — edited May 11 2009
I am making a hash set for a project.

I am supposed to use java.lang.Object.hashCode() for the hash function. This returns any integer yes?

So my internal hash table is an array, with an array size much smaller than the size of integer.

Let's say the internal hash table has an array of 10 elements to start with, and the hash function returns 13, then it will find array index 3, because it reaches 9 and goes back to 0 for 10, 1 for 11 etc.

Is that a good idea?

So can I just use modulus?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 8 2009
Added on May 8 2009
7 comments
559 views