how to check if a string contains only alphabets and space in java
class IsAlpha
{
public static boolean isAlpha(String s) {
return s != null && s.matches("^[a-zA-Z]*$");
}
public static void main(String[] args)
{
String s = "ABCD";
System.out.println("IsAlpha: " + isAlpha(s));
}
}
class IsAlpha
{
public static boolean isAlpha(String s) {
return s != null && s.chars().allMatch(Character::isLetter);
}
public static void main(String[] args)
{
String s = "ABCD";
System.out.println("IsAlpha: " + isAlpha(s));
}
}
class IsAlpha
{
public static boolean isAlpha(String s) {
if (s == null) {
return false;
}
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (!(c >= 'A' && c <= 'Z') && !(c >= 'a' && c <= 'z')) {
return false;
}
}
return true;
}
public static void main(String[] args)
{
String s = "ABCD";
System.out.println("IsAlpha: " + isAlpha(s));
}
}
Also in Java:
- how to make a loop in java
- java
- java 8 findany on null list
- islowercase java
- java double 2 decimal
- bukkit java get max players
- fragment button nullpointerexception
- how to find length of array in java
- cannot lock java compile cache as it has already been locked by this process
- read lines of file randomly java
- padding a string with 0 in java
- keep jframe on top
- dicom read with java
- numberformatexception
- how to calculate min, max and average and write the output into into a text file in java
- protect java
- check if object is empty java 8
- how to get length of integer in java
- number to char java
- jquery set data attribute value
- what is a variable in java
- how to remove all whitespace from string java
- remove item from arraylist in java
- java set example