How to print each character from a string?

前端 未结 3 1708
离开以前
离开以前 2021-01-15 06:55

Is there a way to read a single character at a time from the input and process it, without tokenizing the vocabulary?

3条回答
  •  执笔经年
    2021-01-15 07:00

    The toCharArray() function on Strings might be useful here.

    for(char c : s.toCharArray())
         System.out.println(c);
    

    And to print only the lowercase ones in the string- Thanks @fge

    for(Character c : s.toCharArray()){
            if(Character.isLowerCase(c))
            System.out.println(c);
    }
    

提交回复
热议问题