0

I have list of numbers like this:

-153
-542
-153
-153
-783
-785
-975
-153
-478

as you see "153" is showen 4 times but i want to show this number one time only like this:

-153
-542
-783
-785
-975
-478

EDIT:

i need to get all messages numbers but show only one if similar numbers here is my method:

    public static List<SMSData> getAllNumbers(Context context){

    List<SMSData> smsList = new ArrayList<SMSData>();

    Uri uri = Uri.parse("content://sms/inbox");
    Cursor c= context.getContentResolver().query(uri, null,null,null,null);

    // Read the sms data and store it in the list
    if(c.moveToFirst()) {
        for(int i=0; i < c.getCount(); i++) {

            SMSData sms = new SMSData();
            sms.setBody(c.getString(c.getColumnIndexOrThrow("body")).toString());
            sms.setNumber(c.getString(c.getColumnIndexOrThrow("address")).toString());
            sms.setDate(c.getString(c.getColumnIndexOrThrow("date")).toString());
            smsList.add(sms);


            c.moveToNext();
        }
    }
    return smsList;
}

i fond the solution:

https://stackoverflow.com/a/19305534/3522182

tnx all.

Community
  • 1
  • 1
ali-star
  • 706
  • 1
  • 10
  • 19

1 Answers1

0
    ArrayList yourList = new ArrayList();
/*
add your values to the list
*/
    ArrayList simpleList = new ArrayList();

    HashSet hashset = new HashSet();
    hashset.addAll(yourList);

    simpleList.addAll(hashset);// your list now has the unique numbers

NOTE: the order here is unexpected. if you want it orderd, use linkedHashSet for keeping the same order.

Hossam Alaa
  • 663
  • 5
  • 9