Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Delete Repeats in an Array  RSS feed

 
Rebecca Berry
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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:


 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • 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.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • 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).

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!