String类中getChars方法的用法

原创
2018/10/30 11:23
阅读数 1.7K
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: 


 

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
0 收藏
0
分享
返回顶部
顶部