Sorted list of contacts having duplicates ,why?

前端 未结 7 1192
青春惊慌失措
青春惊慌失措 2020-12-07 02:26

I have sorted and listed my phone contacts in to an arraylist but ,i got many duplicates of same contact names in the list .How this happens? how to avoid this?

This

7条回答
  •  甜味超标
    2020-12-07 02:59

    HashSet add items in key/value pair and also remove duplicate entry from item set.

    List phone_num_list= new ArrayList<>();
    // add elements to phone_num_list, including duplicates
    Set hs = new HashSet<>();
    hs.addAll(phone_num_list);
    phone_num_list.clear();
    phone_num_list.addAll(hs);
    

    Happy coding!!

提交回复
热议问题