Check if the characters of a given string are in alphabetical order | Java implementation of above approach ; Function that checks whether the string is in alphabetical order or not ; if element at index ' i ' is less than the element at index ' i - 1' then the string is not sorted ; Driver code ; check whether the string is in alphabetical order or not
public class GFG { static boolean isAlphabaticOrder ( String s ) { int n = s . length ( ) ; for ( int i = 1 ; i < n ; i ++ ) { if ( s . charAt ( i ) < s . charAt ( i - 1 ) ) { return false ; } } return true ; } static public void main ( String [ ] args ) { String s = " aabbbcc " ; if ( isAlphabaticOrder ( s ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }