Q1: - Is it guaranteed that collections, such as Map or Set, will compare keys according to their contents, and not a link?
A1: - No. Collection, map and set are interfaces. The only thing they assure is the contract of possible methods.
Q2: - Depends on the actual implementation, for example HashMap?
A2: Yes. How the class relates to matching is the decision of the developer.
HashMap uses two things to place its objects.
First up is Object#hashCode() , which is used to calculate the index.
The second is Object#equals() , which is used, then a hash collision takes place.
source share