Program to compress a string of characters
For better performance you should be able to eliminate the Hashmap and use a StringBuilder to count and build the compressed string in one operation:

public static String Compress(String input)
{
    StringBuilder sb = new StringBuilder();
    int i = 0;
    int limit = input.length() - 1;
    char next = '\0';
    while (i &lt; limit)
    {
        int count = 1;
        next = input.charAt(i++);
        while (i &lt;= limit &amp;&amp; next == input.charAt(i))
        {
            count++;
            i++;
        }
        sb.append(next);
        sb.append(count);
    }
    if(i == limit)
    {
        sb.append(input.charAt(i));
        sb.append(1);
    }
    return sb.toString();
}


Caveat:  This code won't work with the full unicode set