Question : how to check if a string contains only alphabets and numbers in java
Answered by : nat-santos
string.matches("[a-zA-Z]*"); // return true if it has only letters
string.matches("[0-9]*"); // return true if it has only numbers
string.matches("[a-zA-Z0-9]*"); // return true if it has only letters and numbers
Source : | Last Update : Tue, 12 Jul 22
Question : how to check whether a character is alphabet or not in java
Answered by : nice-newt-jwphf8kbegan
//Long version:
private (static) boolean isAlphabet(char c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
}
//SHort version:
private (static) boolean isAlphabet(char c) { return if (c in 'a'..'z' || с in 'A'..'Z' || c in '0'..'9');
}
Source : | Last Update : Fri, 11 Feb 22
Question : how to check whether a character is vowel in java
Answered by : wissam-fawaz
public class CodeGrepper { public static boolean isVowel(char letter) { String vowels = "aeouiAEOUI"; return vowels.indexOf(letter) != -1; } public static void main(String[] args) { System.out.println(isVowel('a')); // true System.out.println(isVowel('z')); // false }
}
Source : | Last Update : Thu, 14 Apr 22
Question : check if string contains only letters java
Answered by : abdel
String.matches("[a-zA-Z]+")
Source : https://www.tutorialkart.com/java/how-to-check-if-string-contains-only-alphabets-in-java/ | Last Update : Thu, 19 May 22