Convert a String to an Array and Back Again without Duplicates

I am looking for the best way to convert a String to an Array and Back Again without any Duplicates.

Basically I have a comma delimited string that includes names.  I want to return a string that contains a comma delimited string but without any duplicates.
lasuttonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
Try
            List unique = new ArrayList(new HashSet(new ArrayList(Arrays.asList(array))));
UrosVidojevicCommented:
You will have to use
String[] split(String regex)
method in String class and then remove duplicates manualy.
CEHJCommented:
Sorry:

array = (String[])new ArrayList<String>(new LinkedHashSet<String>(new ArrayList<String>(Arrays.asList(array)))).toArray(new String[0]);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

lasuttonAuthor Commented:
And to move the list back into a delimited string, do I need to loop through each element and add to the new String?
lasuttonAuthor Commented:
For the...

array = (String[])new ArrayList<String>(new LinkedHashSet<String>(new ArrayList<String>(Arrays.asList(array)))).toArray(new String[0]);

...solution, I then parse through the array and move it into a String manually, or is there something that can do the whole thing in a single line?
CEHJCommented:
>>...solution, I then parse through the array and move it into a String manually, or is there something that can do the whole thing in a single line?

Yes, you do. Unfortunately there's no 'join' method in Java
lasuttonAuthor Commented:
Thanks CEHJ, this works perfectly based on your help:

public String removeRepeatingElementsInDelimitedString(String aStringToParse) throws Exception {
      String[] originalList = aStringToParse.split(",");
      String noduplicatesListDelimitedResult = "";
      originalList = (String[])new ArrayList<String>(new LinkedHashSet<String>(new ArrayList<String>(Arrays.asList(originalList)))).toArray(new String[0]);
      int newListLength = originalList.length;
      for(int x = 0;x<newListLength;x++)
      {
      noduplicatesListDelimitedResult = noduplicatesListDelimitedResult + originalList[x] + ",";
      }
      noduplicatesListDelimitedResult = noduplicatesListDelimitedResult.substring(0, noduplicatesListDelimitedResult.length()-1);
            
      return noduplicatesListDelimitedResult;
}
CEHJCommented:
Good - it would be better to append using a StringBuilder though
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.