Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Bonsai Boy of New York Bonsai Trees and Accessories

BlueHost Web Hosting

Liquid Web iThemes WordPress Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Liquid Web Cloud VPS Hosting

10,935 questions

14,843 answers

573 users

How to check if a string contains only alphabets letters in Java

2 Answers

0 votes
public class MyClass {
    public static boolean isAlphabet(String s) { 
        return ((!s.equals("")) 
                 && (s != null) 
                 && (s.chars().allMatch(Character::isLetter))); 
    } 

    public static void main(String args[]) {
        String s = "JavaProgramming";

        if (isAlphabet(s))
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


/*
run:

Yes

*/

 




answered Feb 6 by avibootz
0 votes
public class MyClass {
    public static boolean isAlphabet(String s) { 
        if (s == null || s.equals("")) { 
            return false; 
        } 
        for (int i = 0; i < s.length(); i++) { 
            char ch = s.charAt(i); 
            if ((!(ch >= 'A' && ch <= 'Z')) && (!(ch >= 'a' && ch <= 'z'))) { 
                return false; 
            } 
        } 
        return true; 
    } 
 
    public static void main(String args[]) {
        String s = "JavaProgramming";
 
        if (isAlphabet(s))
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}
 
 
/*
run:
 
Yes
 
*/

 




answered Feb 7 by avibootz
...