-3

Now:

enter image description here

I want:

enter image description here

Code:

String[] contact = new String[contact_phoneList.size()];
for (int i = 0; i < contact_phoneList.size(); i++) {
    contact [i] = contact_phoneList.get(i);
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • or https://stackoverflow.com/questions/13912004/remove-duplicates-from-integer-array, or https://stackoverflow.com/questions/10056729/java-remove-duplicates-from-an-array and even https://stackoverflow.com/questions/357421/what-is-the-best-way-to-remove-duplicates-in-an-array-in-java – jhamon Sep 19 '18 at 08:35
  • Just use a `Set` and you'll be fine, or `contact_phoneList.stream().distinct().toArray(String[]::new);` – PPartisan Sep 19 '18 at 08:35
  • accept the answer if it helps..So it will help others – Faiz Mir Sep 19 '18 at 09:01
  • i accepted your answer. ^^ – MmmmBbbbbbbbbbbbbbbbbbbb Sep 19 '18 at 09:04

1 Answers1

3

Use HashSet to remove duplicate values:

HashSet hs = new HashSet();
hs.addAll(contact_phoneList); // name of contact_phoneList from which you want to remove duplicates 
contact_phoneList.clear();
contact_phoneList.addAll(hs);

No need for a for loop

achAmháin
  • 4,176
  • 4
  • 17
  • 40
Faiz Mir
  • 599
  • 5
  • 16