Compress String
Compress String
public static String CompressStr(String str) {
        String ret="";
        if(str != null && str.length() > 0) {
            if(str.length() == 0 || str.length() == 1)
                ret = str;
            else {
                int c=1;
                int i=0;
                for(i=0; i<str.length()-1; i++) {
                    if(str.charAt(i) == str.charAt(i+1))
                        c++;
                    else{
                        if(c > 1) {
                            ret = ret + str.charAt(i) + c + "";
                            c=1;
                        }else{
                            ret = ret + str.charAt(i) + "";
                        }
                    } 
                }

                if(c > 1)
                    ret = ret + c	+ str.charAt(i) + "";
                else
                    ret = ret + str.charAt(i) + "";
            }
        }
        return ret;
    }

    public static String compress(String str) {
        int c = 1;
        String retStr = "";
        int i=0;
        for(; i<str.length()-1; i++) {
            if(str.charAt(i) == str.charAt(i+1)) {
                c++;
            } else {
                if(c == 1)
                    retStr += str.charAt(i) + "";
                else if(c > 1)
                    retStr += str.charAt(i) + "" + c;

                c = 1;
            }
        }

        if(c == 1)
            retStr += str.charAt(i) + "";
        else if(c > 1)
            retStr += str.charAt(i) + "" + c;

        return retStr;
    }

    public static String compress2(String str) {
        int c = 1;
        String retStr = "";
        str += "0";
        for(int i=0; i<str.length()-1; i++) {
            if(str.charAt(i) == str.charAt(i+1)) {
                c++;
            } else {
                if(c == 1)
                    retStr += str.charAt(i) + "";
                else if(c > 1)
                    retStr += str.charAt(i) + "" + c;

                c = 1;
            }
        }

        return retStr;
    }