A hastable uses some hash function for an object to store.
This hash function essentially calculates the position of an object in a table.
If we use a HashTable or HashMap , and the size cannot fit into more elements, then these collections will be resized to accommodate more elements.
This means that each saved item needs to be rephrased to calculate a new position in a new larger table.
My question is the following (which is true above):
I read that String computes its hashcode using the characters it stores, and additionally that hashvalue is stored internally (cached) for better performance, since it does not need to be recalculated.
This is the part that I do not get. If hashcode based on the characters that String stores, then how is the position calculated in a HashTable ?
Is there any additional logic using hashcode from String ? So String hashcode is actually not hashvalue ?
source share