Print the frequency of each character in Alphabetical order | Java implementation of the approach ; Function to print the frequency of each of the characters of s in alphabetical order ; To store the frequency of the characters ; Update the frequency array ; Print the frequency in alphatecial order ; If the current alphabet doesn 't  appear in the string ; Driver code
class GFG { static int MAX = 26 ; static void compressString ( String s , int n ) { int freq [ ] = new int [ MAX ] ; for ( int i = 0 ; i < n ; i ++ ) { freq [ s . charAt ( i ) - ' a ' ] ++ ; } for ( int i = 0 ; i < MAX ; i ++ ) { if ( freq [ i ] == 0 ) continue ; System . out . print ( ( char ) ( i + ' a ' ) + " " + freq [ i ] ) ; } } public static void main ( String [ ] args ) { String s = " geeksforgeeks " ; int n = s . length ( ) ; compressString ( s , n ) ; } }