Detailed hashset implementation without repeating elements
HashSet the Add Method:
Public boolean Add (E E)
If the specified element is not already contained in this set, the specified element is added. More specifically, if this set does not contain an element E2 that satisfies (E==null. E2==null:e.equals (E2)), the specified element e is added to this set. If this set already contains the element, the call does not change the set and returns false.
The Equals method of object:
public boolean equals (Object obj)
Indicates whether an other object is "equal" to this object.
The Equals method implements an equality relationship on a non-null object reference:
Reflexivity: X,x.equals (x) should return true for any non-null reference value.
Symmetry: x.equals (y) should return true for any non-null reference value x and Y, if and only if Y.equals (x) returns True.
Transitivity: For any non-null reference value x, Y, and Z, if X.equals (y) returns true and Y.equals (z) returns True, then X.equals (z) should return true.
Consistency: For any non-null reference value x and Y, multiple calls to X.equals (Y) always return TRUE or always return false, provided that the information used in the Equals comparison on the object has not been modified.
X,x.equals (NULL) should return FALSE for any non-null reference value.
The Equals method of object implements the most differentiated equality relationship on the object, that is, for any non-null reference value x and Y, this method returns True if and only if X and Y refer to the same object (x = = Y has a value of true).
Note: When this method is overridden, it is often necessary to override the Hashcode method to maintain the general contract of the Hashcode method, which declares that the equality object must have an equal hash code.
Java record -56-detailed hashset implementation without repeating elements