A hastable
uses some hash function on an object to store.
This hash function essentially calculates the position of the object in the table.
If we use a HashTable
or HashMap
and the size can not fit more elements then these collections are resized to accomodate more elements.
This means that each stored element must be rehashed to calculate the new position in the new bigger table.
My question is the following(that the above are correct):
I read that String
calculates its hashcode
by using the characters that it stores and additionally that the hashvalue
is stored internally (cached) for best performance since it does not have to be recalculated.
This is the part I don't get.If the hashcode
is based on the characters the String
stores then how is the position in the hashtable
calculated?
Is there some extra logic using the hashcode
of String
? So the String
's hashcode
is not actually the hashvalue
?