\nStringBuffer a = new StringBuffer( " ab ab ab ab " );\n\nint j = 0;\nint i = 0;\nwhile (i < a.length())\n {\n while (i < a.length() && a.charAt(i) == ' ' ) // Change this to a while\n // a.deleteCharAt(i); Don't delete\n i++;\n if (i < a.length())\n {\n a.charAt(j) == a.charAt(i); // Pull the characters forward.\n i++; // walk both forward\n j++;\n }\n }\n
Yeah...you need to clean the code up at the end too....but hey...it's off the top of me head.
(And I'm sure it can be improved.)