title: remove duplicates in Set
body: <p>How can I avoid inserting duplicate elements in a Set? If I have:</p>
  <pre><code> Set&lt;User&gt; user=new HashSet&lt;&gt;();
                              User user1=new User(&quot;11&quot;,&quot;Mark&quot;,null,&quot;1&quot;);
                              User user2=new User(&quot;11&quot;,&quot;Mark&quot;,null,&quot;1&quot;);
                              User user3=new User(&quot;12&quot;,&quot;Helen&quot;,null,&quot;2&quot;);
  
                              user.add(user1);
                              user.add(user2);
                              Log.d(&quot;main_activity_user&quot;, &quot;la dimensione è&quot; +String.valueOf(user.size()));
  </code></pre>
  <p>Adn User class is:</p>
  <pre><code>public class User {
      public String uid;
  public String name;
      public String pversion;
  public String upicture;
      public User(String uid,
              String name,
                  String upicture, String pversion ){
          this.uid=uid;
          this.name=name;
          this.upicture=upicture;
          this.pversion=pversion;
      }
      public String get_uid(){
          return uid;
      }
      public String get_name(){
          return name;
      }
      public String get_pversion(){
          return pversion;
      }
      public String get_upicture(){
          return upicture;
      }
      @Override
      public boolean equals(Object obj) {
          User newObj = (User)obj;
          if (this.get_uid().equals( newObj.get_uid()))
              return true;
          else
              return false;
      }
  }
  </code></pre>
  <p>Now the <code>Set</code> also stores duplicates and prints me 3 elements instead of two. Why?</p>
  <p>I have never used the <code>Set</code> class before and I don't understand it. So, every time I use the <code>Set</code> class, do I have to Override the Equals method? Why? Doesn't the class delete duplicates automatically?</p>