在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’