Until now, I know that after rehashing in a HashMap, all the entries are rehashed with the new table length. But I want to know what will happen when I have collisions.
e.g.
Map<String, String> map = new HashMap<>(5);
map.put("a", "ape");
map.put("b", "bird");
map.put("c", "chicken");
Suppose they have different hashcodes, but "b"
and "c"
are stored in the same bucket after the internal hashing.
Now I'll insert a fourth entry to reach the load factor therefore rehashing the table:
map.put("d", "dynamite");
Could the entries with collisions be stored in separate buckets or they always will be together (in reverse order according of what I've read)?.
I suppose that the answer to the title is no, because I will get the same internal hashing for "b"
and "c"
, but I'm not sure.