Generally the javadoc is easier to read than the code.
add
public boolean add(E e)
Adds the specified element to this set if it is not already present. More formally, adds the specified element e to this set if this set contains no element e2 such that (e==null ? e2==null : e.equals(e2)). If this set already contains the element, the call leaves the set unchanged and returns false.
That's from HashSet.
Because HashSet allows a null element, it checks if there's already a null element if the new one is null. If it's not null, it uses the equals() method found in Object. That implementation returns true if the 2 references are the same and typically a class would override this method and check if the 2 instances are meaningfully equal.
Say your class SomeObject has a
String or 2, it might compare each of those Strings using String's .equals() implementation.