String类中getChars方法的用法

public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin)

 该方法的作用是将当前字符串从srcBegin到srcEnd-1位置上的字符复制到字符数组dst中,并从dst的dstBegin处开始存放

String str = "addd";
char [] dst = new char[6];
//将当前字符串str从0到(4-1)位置上的字符复制到字符数组dst中,并从dst的1处开始存放
str.getChars(0,4,dst,1);
int i = 0;
for (char val:dst) {
  System.out.println("当前索引位置"+(i++)+":"+val);
}

输出结果:

当前索引位置0: 
当前索引位置1:a
当前索引位置2:d
当前索引位置3:d
当前索引位置4:d
当前索引位置5: 


 

猜你喜欢

转载自my.oschina.net/u/3568600/blog/2254530
今日推荐