how to remove duplicate contacts from arraylist

前端 未结 5 1526
谎友^
谎友^ 2021-01-16 21:13

I have created an app in which I am getting the contacts from a device. But I want to remove the duplicate contacts from the results.

How could I do it?

5条回答
  •  执笔经年
    2021-01-16 21:43

    • If you want to get rid of duplicates, consider using a HashSet instead.

    • If you can't/don't want to use it, simply check before adding whether the contact is already there.

      if (!myList.contains(newContact))
        myList.add(newContact);
      

提交回复
热议问题