title: how to remove duplicate contact from contact list in android
body: <p>please have a look :-</p>
  
  <pre><code> public static ArrayList&lt;ContactsEntityBean&gt; getContactDetails(
              Context mContext) {
          ArrayList&lt;ContactsEntityBean&gt; contactList = new ArrayList&lt;ContactsEntityBean&gt;();
          ContentResolver cr = mContext.getContentResolver();
          Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
                  null, null, null);
          if (cur.getCount() &gt; 0) {
              while (cur.moveToNext()) {
                  String id = cur.getString(cur
                          .getColumnIndex(ContactsContract.Contacts._ID));
                  Cursor cur1 = cr.query(
                          ContactsContract.CommonDataKinds.Email.CONTENT_URI,
                          null, ContactsContract.CommonDataKinds.Email.CONTACT_ID
                                  + " = ?", new String[] {
                              id
                          }, null);
                  while (cur1.moveToNext()) {
                      ContactsEntityBean contactsEntityBean = new ContactsEntityBean();
                      // to get the contact names
                      String name = cur1
                              .getString(cur1
                                      .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
  
                      // Log.e("Name :", name);
                      String email = cur1
                              .getString(cur1
                                      .getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
  
                      // Log.e("Email", email);
                      contactsEntityBean.setName(name);
                      contactsEntityBean.setEmail(email);
                      if (email != null) {
                          contactList.add(contactsEntityBean);
                      }
                  }
                  cur1.close();
              }
          }
          return contactList;
      }
  </code></pre>
  
  <p>this method is return multiple contact from same user suppose if i have stored abc@gmail.com,abc@gmail.com for same user so it is returning abc@gmail.com&amp; abc@gmail.com
  but i want only one record abc@gmail.com </p>
  
  <pre><code> public static ArrayList&lt;SearchEntityBean&gt; getContactEmailDetails(
              Context mContext) {
          ArrayList&lt;SearchEntityBean&gt; contactList = new ArrayList&lt;SearchEntityBean&gt;();
  
  
          try {
              ContentResolver cr = mContext.getContentResolver();
              Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
                      null, null, null);
              if (cur.getCount() &gt; 0) {
                  while (cur.moveToNext()) {
                      String email = "";
                      String id = cur.getString(cur
                              .getColumnIndex(ContactsContract.Contacts._ID));
  
                      Cursor cur1 = cr.query(
                              ContactsContract.CommonDataKinds.Email.CONTENT_URI,
                              null,
                              ContactsContract.CommonDataKinds.Email.CONTACT_ID
                                      + " = ?", new String[] {
                                  id
                              }, null);
                      SearchEntityBean contactsEntityBean = new SearchEntityBean();
                      while (cur1.moveToNext()) {
  
                          // to get the contact names
  
                          String name = cur1
                                  .getString(cur1
                                          .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
                          String image = cur1
                                  .getString(cur1
                                          .getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_ID));
                          String mail = cur1
                                  .getString(cur1
                                          .getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
  
                          if (mail != null) {
                              if (!mail.equalsIgnoreCase(LoginPreferenceClass
                                      .getEmailID(mContext)))
                                  email = email + mail + ",";
                          }
                          // Log.e("rohit", "Contact  Email :" + email);
                          contactsEntityBean.setName(name);
                          contactsEntityBean.setImage(image);
  
                      }
  
                      if (email != null) {
  
                          if (email.length() &gt; 0) {
  
                              if (email.split(",").length &gt; 1) {
  
                                  contactsEntityBean.setMutipleEmail(true);
  
                              }
  
                              contactsEntityBean.setUserType("2");
                              contactsEntityBean.setContactId(id);
                              contactsEntityBean.setEmail(email);
                              contactList.add(contactsEntityBean);
                          }
                      }
                      cur1.close();
                  }
              }
          } catch (Exception e) {
              e.printStackTrace();
          }
          HashSet&lt;SearchEntityBean&gt; hs = new HashSet&lt;SearchEntityBean&gt;();
          hs.addAll(contactList);
          contactList.clear();
          contactList.addAll(hs);
          return contactList;
      }
  </code></pre>