If a Hashtable is of size 8 originally and we hit the load factor and it grows double the size. How is get still able to retrieve the original values … so say we have a hash function key(8) transforms into 12345 as the hash value which we mod by 8 and we get the index 7 … now when the hash table size grows to 16 …for key(8) we get 12345 .. if we mod it by 16 we will get a different answer! So how do i still retrieve the original key(8)
Share
This isn’t Java specific – when a hash table grows (in most implementations I know of), it has to reassess the keys of all hashed objects, and place them into their new, correct bucket based on the number of buckets now available.
This is also why resizing a hashtable is generally considered to be an “expensive” operation (compared to many others) – because it has to visit all of the stored items within it.