We store all the indexes of maximum characters we have in the string
for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str . charAt ( i ) >= maxchar ) { maxchar = str . charAt ( i ) ; index . add ( i ) ; } } String maxstring = " " ;