在Java中,charAt()方法用于获取字符串中指定位置的字符。
常见用法如下:
示例:String str = “Hello World”; char ch = str.charAt(4); // ch的值为’o’
示例:String str = “Hello World”; int len = str.length(); // len的值为11
示例:char ch = ‘A’; boolean isLetter = Character.isLetter(ch); // isLetter的值为true
示例:char ch = ‘5’; boolean isDigit = Character.isDigit(ch); // isDigit的值为true
示例:char ch = ’ '; boolean isWhitespace = Character.isWhitespace(ch); // isWhitespace的值为true
示例:char ch = ‘A’; boolean isUpperCase = Character.isUpperCase(ch); // isUpperCase的值为true
示例:char ch = ‘a’; boolean isLowerCase = Character.isLowerCase(ch); // isLowerCase的值为true
示例:char ch = ‘a’; char upperCh = Character.toUpperCase(ch); // upperCh的值为’A’
示例:char ch = ‘A’; char lowerCh = Character.toLowerCase(ch); // lowerCh的值为’a’