In Java, how to find if first character in a string is upper case without regex

后端 未结 8 1641
广开言路
广开言路 2020-11-30 04:39

In Java, find if the first character in a string is upper case without using regular expressions.

8条回答
  •  清歌不尽
    2020-11-30 05:16

    Assuming s is non-empty:

    Character.isUpperCase(s.charAt(0))
    

    or, as mentioned by divec, to make it work for characters with code points above U+FFFF:

    Character.isUpperCase(s.codePointAt(0));
    

提交回复
热议问题