Checking for Alphabets in a String in java

后端 未结 6 1453
灰色年华
灰色年华 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:23

    Try

        String s = "BC+D*E-=";
    
        for (int i = 0; i < s.length(); i++) {
            char charAt2 = s.charAt(i);
            if (Character.isLetter(charAt2)) {
                System.out.println(charAt2 + "is a alphabet");
            }
        }
    

提交回复
热议问题