I
I
Igor2018-12-06 14:51:15
Java
Igor, 2018-12-06 14:51:15

How does a Java program behave if there are several DIFFERENT objects with the same HashCode in the HashSet?

Are there any additional checks between such objects?
What is the algorithm for dealing with such collisions?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2018-12-06
@hddn

They will be added to one bucket, and they will be retrieved by iterating the bucket with a method call equalsfor each element.
how+hashmap+works+internally+in+java+.pn

C
Cheypnow, 2018-12-06
@Cheypnow

Depends on how equals() works for them.
Actually, if equals() returns true, then they simply will not be added to the Set initially.
If they are nevertheless added, they will lie in one cell, which will be iterated during extraction.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question