Andy897
Andy897

Reputation: 7133

Iterating over hashmap in case of collision in Java

Let us say we have a collision but key values are different, so by definition Hashmap will create a linked list at that bucket and add the new key value pair as the next of existing key value entry.

My question is how do we iterate over the hashmap in this case ? Does the default iteration mechanism changes to actually retrieve all the key value pairs which collided and got stored in the same bucket location ?

Upvotes: 1

Views: 286

Answers (1)

SMA
SMA

Reputation: 37023

There are no changes. It would iterate over like say bucket 0 i.e. every elements in bucket and then move to bucket 1 and so on. So there are no changes in the way it would iterate.

Upvotes: 1

Related Questions