java.lang.String.charAt() 方法
阿新 • • 發佈:2019-02-19
java.lang.String.charAt() 方法返回指定索引處的char值。索引範圍是從0到length() - 1。對於陣列索引,序列的第一個char值是在索引為0,索引1,依此類推,
宣告
以下是宣告java.lang.String.charAt()方法
public charcharAt(int index)
引數
· index -- 這是該指數的char值.
返回值
此方法返回這個字串的指定索引處的char值。第一個char值的索引為0.
異常
· IndexOutOfBoundsException -- 如果index引數為負或不小於該字串的長度
執行結果:public class CharAt { public static void main(String[] args) { String s = "bejing welcome you"; System.out.println(s.charAt(1)); System.out.println(s.charAt(5)); System.out.println(s.charAt(15)); } }
e
g
y