• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Delete Repeats in an Array

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again all!  So I have created a program to delete the repeats in an array.  It seems to be working with one exception.  I need the results to have a comma separating all the letters. So instead of the results displaying as a,bc I need them to display as a,b,c. Any advise on how to solve this issue? As always thanks for the input.
Here is my code:
import java.util.Arrays;




And here is the output:


 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you add some comments to the code describing what it is trying to do and how it is going to do it?

Note: The code is poorly formatted making it harder to read and understand.  There is a lot of code that is not properly indented to show nesting levels.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so your deleteRepeats method takes a string.
It declares an array large enough to hold every element.
you then loop through every character in the string. And commas are characters.
You check to see if the current character is in the array, and if not, you add it in. So the first time you see a comma character, it gets added into your table array.

when you are done you return the contents of the array as a string, which will only have one comma in it.

when the string is passes in to your method, java doesn't know that you have elements separated by commas...it just sees a single string with 8 (or whatever) characters, and it is therefor finding the unique characters.

So you need to somehow separate the DATA (a b c) from the SEPARATORS (the commas).

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic