Re: delete repeated letters in a word
- From: Michael Rauscher <michlmann@xxxxxx>
- Date: Fri, 09 Feb 2007 13:10:06 +0100
spidey12345 wrote:
ok, fine, i am using hashset:)
but which function in there allow me to delete repeated values or 0,
that is not character
Why do you use an array? You don't even need a HashSet if speed doesn't matter.
Untested (I even didn't tried to compile it) code:
public String removeDuplicateLetters( String word ) {
if ( word == null )
return null;
StringBuilder builder = new StringBuilder();
for ( int i = 0, n = word.length(); i < n; i++ ) {
String sub = word.substring(i,i+1);
if ( builder.indexOf(sub) == -1 )
builder.append(sub);
}
return builder.toString();
}
If you want to use a HashSet due to performance reasons the only thing you'd have to replace is the if-condition and of course, you'd have to add the element to the Set.
Bye
Michael
.
- Follow-Ups:
- Re: delete repeated letters in a word
- From: Daniel Pitts
- Re: delete repeated letters in a word
- References:
- delete repeated letters in a word
- From: spidey12345
- Re: delete repeated letters in a word
- From: Oliver Wong
- Re: delete repeated letters in a word
- From: spidey12345
- Re: delete repeated letters in a word
- From: Oliver Wong
- Re: delete repeated letters in a word
- From: spidey12345
- delete repeated letters in a word
- Prev by Date: Re: problem splitting a string
- Next by Date: GridBagLayout and its pitfals
- Previous by thread: Re: delete repeated letters in a word
- Next by thread: Re: delete repeated letters in a word
- Index(es):
Relevant Pages
|