java中charAt()方法的使用


charAt(int index)方法是一个能够用来检索特定索引下的字符的String实例的方法.

charAt()方法返回指定索引位置的char值。索引范围为0~length()-1.

如: str.charAt(0)检索str中的第一个字符,str.charAt(str.length()-1)检索最后一个字符.

package com.xumingjie.s;

public class Cartat {
public static void main(String[] args) {

String str = "This is yiibai";

// prints character at 1st location
System.out.println(str.charAt(0));

// prints character at 5th location i.e white-space character
System.out.println(str.charAt(4));

// prints character at 18th location
System.out.println(str.charAt(6));
}

}

结果如下:

T

s

java中charAt()方法的使用介绍到这里,更多java学习请参考编程字典java教程 和问答部分,谢谢大家对编程字典的支持


原文链接:https://blog.csdn.net/jim_cainiaoxiaolang/article/details/51820074?ops_request_misc=&request_id=&biz_id=102&utm_term=java&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~sobaiduweb~default-7-51820074.nonecase&spm=1018.2226.3001.4450