I'm trying to learn how the HashMap class works. I have this big textfile with "all" countrys with their name, capital, poupulation and so on. And I want to add them to a hashmap, with the name of the country as a key.
My question is:
Do I have to use a hashfunction when I'm using HashMap? Because I read this somewhere, how to calculate the table index of a element using a hashfunction and modulus:
But I can't see that people are using a hashfunctions to decide positioning, when they are using HashMap.Code:
index(”Sweden”) = hashfunction(”Sweden”) mod lenght(hashTableSize) = 4
h = 17;
for all chars c in string do:
h is put to the value of h * 31 + asciivalue for c
I'm kind a confused about all this, so can someone please explaine in simple words how this works?