1

Im trying to convert a string array with duplicates to string array without duplicates by using hashSet like below.

String[] d = new HashSet<String>(Arrays.asList(duplicateList)).toArray(new String[0]);


duplicateList = AD,AD,AD,AD,AD,AD,AD,AD,AD,AD,CP,RR,RR,RR,RR,RR,RR,,,,,,,,,,,

When I print d its still the same. Am i missing something?

Note: I do not want to loop through and use contains or equals.

Geek
  • 3,187
  • 15
  • 70
  • 115

1 Answers1

2

Try something like this. That should be it.

d.addAll(Arrays.asList(duplicateList.split(",")));

peter.petrov
  • 38,363
  • 16
  • 94
  • 159