Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Method to remove Duplicate char from a StringBuilder

843785Jul 8 2008 — edited Jul 11 2008
hello,

I'm trying to create a method to remove duplicate char from a Stringbuilder so if I inputted 'ttttttt' I would
only be returned with 't' my method at the moment is
public static String Dups(String aString)
{
StringBuilder aSB = new StringBuilder(aString);

for (int i = 0;i<aSB.length();i++)
   {
      if(aSB.charAt(i)==aSB.charAt(i++))
      {
      aSB.deleteCharAt(i);
      }
   }
return aSB.toString();
}
The code is remove some 't''s but not all duplicates
does anyone know where I'm going wrong?

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 8 2008
Added on Jul 8 2008
11 comments
1,227 views