title: Store a list of objects without duplicates in a database DAO
body: <p>How do I store a list of objects without duplicates in a database?
  I have my database DAO:</p>
  <pre><code>@Dao
  public interface UserDAO {
      @Query(&quot;select*from User&quot;)
      List&lt;User&gt; getAll();
      @Insert
      void insertAll(User...users);
  }
  </code></pre>
  <p>User class have:</p>
  <pre><code>@Entity(indices = {@Index(value = {&quot;name&quot;}, unique = true)})
  public class User {
  @ColumnInfo(name=&quot;name&quot;)
  public String name;
  @ColumnInfo(name=&quot;surname&quot;)
  public String surname;
  @PrimaryKey @NonNull
  public String uid;
  </code></pre>
  <p>I recover some users from the school server and I have duplicate users and I want store some Users without duplicates in my database DAO:</p>
  <pre><code>Model_user.getInstance(activity.getApplicationContext()).addUser(
                                          new User(
                                                  uid,
                                                  name,
                                                  surname));
  </code></pre>
  <p>I want store for example:<code>[&quot;11&quot;,&quot;Jenny&quot;,&quot;McCart&quot;],[&quot;12&quot;,&quot;Mark&quot;,&quot;McBack&quot;]</code> instead I store:<code>[&quot;11&quot;,&quot;Jenny&quot;,&quot;McCart&quot;],[&quot;12&quot;,&quot;Mark&quot;,&quot;McBack&quot;],[&quot;11&quot;,&quot;Jenny&quot;,&quot;McCart&quot;]</code></p>