title: Retrieve only data from snapshot present in ArrayList firebase android
body: <p>I have 2 arraylist. one of contact list present in my phone book, and other of phone numbers in my database.</p>
  <p><strong>Getting contacts from PhoneBook.</strong></p>
  <pre><code>    private void getArrayListDataFromPhonebook(ContentResolver contentResolver) {
  //        ContentResolver cr = getContentResolver();
  
          Cursor cursor = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, ContactsContract.Contacts.SORT_KEY_PRIMARY + &quot; ASC&quot;);
          if (cursor != null) {
              HashSet&lt;String&gt; mobileNoSet = new HashSet&lt;String&gt;();
              try {
                  final int nameIndex = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
                  final int numberIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
  
                  String name, number;
                  while (cursor.moveToNext()) {
                      name = cursor.getString(nameIndex);
                      number = cursor.getString(numberIndex);
                      number = number.replace(&quot; &quot;, &quot;&quot;);
                      if (!mobileNoSet.contains(number)) {
  //                        contactListFromPhoneBook.add(new Contact(name, number));
  
  
                          contactListFromPhoneBook.add(number);
                          Log.d(&quot;contact&quot;, String.valueOf(contactListFromPhoneBook.size()));
  
                          mobileNoSet.add(number);
                      }
                  }
              } finally {
                  cursor.close();
              }
          }
      }
  </code></pre>
  <p><strong>Getting contact From firebase database and comparing with phonebook from my Mobile</strong></p>
  <pre><code>private void getCommonContact(){
  
  ArrayList&lt;String&gt; contactList = new ArrayList&lt;&gt;();
  Set&lt;String&gt; set1 = new HashSet&lt;&gt;();
  Set&lt;String&gt; set2 = new HashSet&lt;&gt;();
  
  FirebaseDatabase mFirebaseDatabase;
  DatabaseReference mDatabaseReference;
  
  mFirebaseDatabase = FirebaseDatabase.getInstance();
  
  mDatabaseReference = mFirebaseDatabase.getReference().child(&quot;users&quot;);
  
  Query myQuery = mDatabaseReference.orderByChild(&quot;username&quot;);
  myQuery.addValueEventListener(new ValueEventListener() {
      @Override
      public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
  
  
          for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
  
              String number = &quot;&quot; + snapshot.child(&quot;phone&quot;).getValue();
              contactList.add(number);
  
              for (String i : contactList) {
                  set1.add(i);
              }
  
              for (String i : contactListFromPhoneBook) {
                  set2.add(i);
              }
  
              set1.retainAll(set2);
              set1.add(number);
  
              Log.d(&quot;set1&quot;, String.valueOf(set1));
  
  
  
  
              StringBuilder sb = new StringBuilder();
              for (String s : set1)
              {
                  sb.append(s);
                  sb.append(&quot;\t&quot;);
              }
  
              System.out.println(sb.toString());
  
          }
      }
  
      @Override
      public void onCancelled(@NonNull DatabaseError databaseError) {
  
      }
  });
  </code></pre>
  <p>}</p>
  <p><strong>Log.d(&quot;set1&quot;, String.valueOf(set1));</strong></p>
  <pre><code>D/set1: [+918460883852, +919045810005, +917383085422, +919875142541, +919856257129, +919112546330, +919930325611]
  </code></pre>
  <p>I am getting all the contact present in firebase database
  All i want is to compare set1 with firebase database and get the common number in recyclerview
  my Holders in bindviewholder are:- holder.mTvUsername  , holder.Tvcontact.
  my recycler</p>