public class TestStringCharAt {
/**
* 主函数
*/
public static void main(String[] args) {
// 测试函数
testStringCharAt();
}
/**
* 了解char charAt(int index)函数,jdk1.7。
* 一句话概括:从字符串中拿到指定索引上的字符。
* 参数:指定索引
* 返回值:指定索引上的字符
* 异常:索引不在字符串索引范围内
* 1.索引 < 0
* 2.索引 >= 字符串长度
*/
public static void testStringCharAt() {
// 从字符串中拿到指定索引上的字符。
System.out.println("0123456789".charAt(0));
// 索引 < 0
// StringIndexOutOfBoundsException: String index out of range: -1 (索引值)
// System.out.println("0123456789".charAt(-1));
// 索引 >= 字符串长度
// StringIndexOutOfBoundsException: String index out of range: 10 (索引值)
// System.out.println("0123456789".charAt(10));
}
}