Java charAt() 方法

Java charAt() 方法

charAt(),用于返回指定索引处的字符,索引范伟从0到str.length()-1(字符串长度减去1,因索引是从0开始的)

语法:

public char charAt(int index)

 参数: index 是字符的索引。

返回值:返回指定索引处的字符。

public class test{
    public static void main(String[] args) {
        String str="www.google.com";
        char cha=str.charAt(4);
        System.out.println("索引4的字符是:"+cha);
    }
}        

 以上程序执行的结果为:

索引4的字符是:g

  

原文地址:https://www.cnblogs.com/henrypaul/p/12185906.html