public static String countSort(String str)
    {
        char[] alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m',
                            'n','o','p','q','r','s','t','u','v','x','y','z'};
        int[] alphaCount = new int[26];
        StringBuilder sb = new StringBuilder();
        
        //count occurences of alphabet letter
        for(int i = 0; i < str.length(); i++)
            for(int j = 0; j < alphabet.length; j++)
                if(str.charAt(i) == alphabet[j])
                    alphaCount[j]++;
        
        for(int i = 0; i < alphaCount.length; i++)
        {
            int n = 0;
            if(alphaCount[i] > 0)//found a letter 
                n = alphaCount[i];
            
            for(int j = 0; j < n; j++)//append letter n times
                sb.append(alphabet[i]);
        }
        return sb.toString();
    }