how to check if a string contains only alphabets and space in java how to check if a string contains only alphabets and space in java

The solution for “how to check if a string contains only alphabets and space in java how to check if a string contains only alphabets and space in java” can be found here. The following code will assist you in solving the problem.

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) {
        return s != null && s.matches(“^[a-zA-Z]*$”);
    }
 
    public static void main(String[] args)
    {
        String s = “ABCD”;
        System.out.println(“IsAlpha: ” + isAlpha(s));
    }
}

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in