Method equals
The documentation of set says "sets contain no pair of elements e1 and e2 such that e1.equals(e2)". The equals method returns true if the e1 and e2 are in some way equal. It may be different from two objects being identical. There can be two distinct objects that are equal. For example, we could have a color implementation that has the name of the colors as an attribute and two color objects may return true calling the equals method on one of them and passing the argument as the other when the two strings are equal. The default implementation of the equals method is in the code of the Object class and this returns true if and only if e1 and e2 are exactly the same and single object.
It seems to be obvious, but my experience ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access