how to check is alphabet in java code example

Example 1: how to check if a string is in alphabetical order in java

public static boolean checkAlphabetic(String input) {
    for (int i = 0; i != input.length(); ++i) {
        if (!Character.isLetter(input.charAt(i))) {
            return false;
        }
    }

    return true;
}

Example 2: java letter alphabet index

String str = "abcdef";
char[] ch  = str.toCharArray();
for(char c : ch){
    int temp = (int)c;
    int temp_integer = 96; //for lower case
    if(temp<=122 & temp>=97)
        System.out.print(temp-temp_integer);
}

Tags:

Java Example