Checking for Alphabets in a String in java

后端 未结 6 1496
灰色年华
灰色年华 2021-01-16 21:46

I have a string \"BC+D*E-\". I want to check each character of the string whether it is an alphabet or not. I tried using isLetter() but it does consider even the = , * and

6条回答
  •  孤独总比滥情好
    2021-01-16 22:28

    Break the String into an array and iterate over it.

    String word = "BC+D*E-"
    for (char c : word.toCharArray()) {
        if(!(Character.isLetter(c)) {
            System.out.println("Not a character!");
            break;
        }
    }
    

提交回复
热议问题