Bhavya Sharma
Bhavya Sharma

Reputation: 427

Use of equals() method in HashSet

I read somewhere that equals() method is used to determine if two objects in HashSet are considered to be same or not.I am bit confused with my understanding.Can anyone explain the scenario please. Thanks in advance.

Upvotes: 1

Views: 51

Answers (1)

Eran
Eran

Reputation: 394126

equals is used to determine if the object you are trying to add or search for already exists in the HashSet. It's not used to determine if two objects in the HashSet are considered the same, since two such objects can't both be in the HashSet.

Upvotes: 1

Related Questions