Basically i am using the hasCode() from the Objects class to obtain a hash code of some strings.
I want that number to represent a position in the array. Basically a hash table. I havent written code for this yet.
I had in mind:
int hashNumber = SomeString.hascode(), pos;
String array[] = new String[10];
if (hashNumber > 0)
pos = hashNumber % array.length
if (hasNumber < 0 )
//dont know what to do
I do know for a fact that hashCode can return a negative integer. What to do if its negative integer? i though about adding the array length
pos = hashNumber + array.length
is this the best way?
thanks in advance