charAt方法 -- 提取指定字符


public class TestString {
    
    public static char testCharAt(String str,int index){
        if((index<0) || (index >= str.length())){
            throw new StringIndexOutOfBoundsException(index);
        }
        char[] c1 = str.toCharArray();
        System.out.println("字符串["+str+"]索引"+index+"爲:"+c1[index]);
        return c1[index];
    }

    public static void main(String[] args) {
        TestString.testCharAt("abcd", 2);
    }
    

}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章