HashSet uses hashCode() and equals() methods to check for duplicates.
When you add an object to a HashSet, it uses the object's hashCode() to find its storage bucket. Then, it uses equals() to check if the object already exists in the bucket. If both methods confirm uniqueness, the object is added.