Remove duplicate in a string without using arrays
<pre><code>    String input = "AAAB";

    String output = "";
    for (int index = 0; index &lt; input.length(); index++) {
        if (input.charAt(index % input.length()) != input
                .charAt((index + 1) % input.length())) {

            output += input.charAt(index);

        }
    }
    System.out.println(output);
</code></pre>

<p>But it doesn't work if my input is "ABABAB" or just "AAAA". Any ideas?</p>
