In Java, find if the first character in a string is upper case without using regular expressions.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Don't forget to check whether the string is empty or
null
. If we forget checkingnull
or empty then we would getNullPointerException
orStringIndexOutOfBoundException
if a given String is null or empty.Assuming
s
is non-empty:or, as mentioned by divec, to make it work for characters with code points above
U+FFFF
:There is many ways to do that, but the simplest seems to be the following one:
we can find upper case letter by using regular expression as well
for detailed example . please visit http://www.onlinecodegeek.com/2015/09/how-to-determines-if-string-starts-with.html
If you have to check it out manually you can do
int a = s.charAt(0)
If the value of a is between 65 to 90 it is upper case.