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?
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);