For each lowercase English alphabet find the count of strings having these alphabets | Java program to find count of Strings for each letter [ a - z ] in english alphabet ; Function to find the countStrings for each letter [ a - z ] ; Initialize result as zero ; Mark all letter as not visited ; Loop through each Strings ; Increment the global counter for current character of String ; Instead of re - initialising boolean vector every time we just reset all visited letter to false ; Print count for each letter ; Driver program ; Given array of Strings ; Call the countStrings function
class GFG { static void CountStrings ( String [ ] str ) { int size = str . length ; int [ ] count = new int [ 26 ] ; boolean [ ] visited = new boolean [ 26 ] ; for ( int i = 0 ; i < size ; ++ i ) { for ( int j = 0 ; j < str [ i ] . length ( ) ; ++ j ) { if ( visited [ str [ i ] . charAt ( j ) - ' a ' ] == false ) count [ str [ i ] . charAt ( j ) - ' a ' ] ++ ; visited [ str [ i ] . charAt ( j ) - ' a ' ] = true ; } for ( int j = 0 ; j < str [ i ] . length ( ) ; ++ j ) { visited [ str [ i ] . charAt ( j ) - ' a ' ] = false ; } } for ( int i = 0 ; i < 26 ; ++ i ) { System . out . print ( count [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { String [ ] str = { " i " , " will " , " practice " , " everyday " } ; CountStrings ( str ) ; } }