I have a StringBuffer which contains duplicates value like the one shown on the left hand side of the example and want to convert it to the one showm on right. Two cases are shown below
{1,1,1,2,2,} to `{1,2}`
{a,a,a,b,c,c,c,}
to {a,b,c}
Please also note that the content and size of StringBuffer is not fixed. I want to solve this problem just by string manipulation.
Well here's a solution that works for duplicates that are not adjacent. It is a bit clunky though...
Note, if you didn't know which items were duplicated, you'd have to call this on every item in your StringBuffer. (Well once per unique item in your StringBuffer.)
For example you could do:
This would avoid removing the "1" from "16", "10", etc. while still removing the other occurence of "1".