I've seen examples on how to create a hash for a string. Here is one example in Java:
private int getHashCode(String text) {
int hash = 7;
for (int i = 0; i < text.length(); i++) {
hash = hash * 31 + text.charAt(i);
}
return hash;
}
This of course can produce large numbers. If I am storing my strings in an array and I have only say 10 array items, how do I calculate the array index from the hash code? I can of course use a HashMap to do this, but I want to do this as part of learning how indexes are created from hash codes.