Maximum occurrence of prefix in the Array | Java program to find the number of occurrences of prefix which occurs maximum no . of time ; Function to return the count of the required prefix ; Find the frequency of first character of string ; Driver code
class GFG { static int prefixOccurrences ( String str ) { char c = str . charAt ( 0 ) ; int countc = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str . charAt ( i ) == c ) countc ++ ; } return countc ; } public static void main ( String args [ ] ) { String str = " abbcdabbcd " ; System . out . println ( prefixOccurrences ( str ) ) ; } }