how to check if all elements of a string are alphabets 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: check element is alphabet java
class Main {
public static void main(String[] args) {
char c = 'a';
if (Character.isAlphabetic(c)) {
System.out.println(c + " is an alphabet.");
}
else {
System.out.println(c + " is not an alphabet.");
}
}
}