821046 wrote:As per API, "sets contain no pair of elements e1 and e2 such that e1.equals(e2)". Because of the equals() method, we also require a proper implementation of the hashCode() method.
As per the Java API contract, to store elements properly inside Set, we should have correct implementation of hashCode() method.
Set will store only 1 element because hashCode for both y1 and y2 will be same i.e 00047As jverd pointed out, only if you have respected the contract of both equals and the hashCode methods, will Set store the elements as expected. Only with the hashCode() it cannot be achieved.