In selected contact i am having duplicate values so that iam first taking copy of selected contact copy
for(int q=0;q<selectedcontact.size();q++)
{
selectedcontactcopy.add(selectedcontact.get(q));
}
and then Comparing two array list
for(int r=0;r<selectedcontactcopy.size();r++)
{
for(int j=0;j<selectedcontact.size();j++)
{
if(r!=j && r<j)
{
if(selectedcontactcopy.get(r).getLandLineNumber().toString().trim().equals(selectedcontact.get(j).getLandLineNumber().toString().trim()))
{
Log.i("hai",selectedcontact.get(j).getLandLineNumber().toString());
selectedcontact.remove(j);
j--;
}
}
}
}
But the situation is that first duplication is avoided then the arraylist won’t compare the next consecutive values
This is a bad way of doing a uniqueness check. A better method is to make use of the functionality of
java.util.Set– make sure your contacts implement Comparable and compare landline numbers, and then add them to the set and iterate over the set contents.Set guarantees you uniqueness, and provides a far cleaner interface than nested for loops.