title: Item not adding to HashSet unless I declare it locally
body: <p>I have a <code>HashSet&lt;User&gt;</code> and a User declared outside a while loop, and inside the loop I am setting the name with a setter method and then adding the User to the <code>HashSet</code> with <code>add(User)</code>. </p>
  
  <p>This seemed to only <em>update</em> the single User in the <code>HashSet</code>. Only when I declare the User within the while loop is a new User added every time to the <code>HashSet</code>. </p>
  
  <p>I am thinking this is because if the <code>HashSet add() method</code> receives an object with the same memory address as an object currently in the set, it will only update the object and not add another new object to the HashSet. Is this correct? </p>
  
  <p>Then instantiating the User within the loop will cause it to have a different memory address and thus be added to the <code>HashSet</code> as a new object.</p>
  
  <p>I can put code on here, but this is for an assignment and I don't think my professor would like me to share code. The question I have is more about the Java language and not about my assignment, as you can see. If everyone absolutely needs to see code, however, I'll post something useful. </p>