java.lang.StringBuilder.getChars()%uA0方法复制此序列到目标字符数组dst的字符。
要复制的第一个字符的索引srcBegin要复制最后一个字符在索引srcEnd- 1个字符被复制的总数是srcEnd- srcBegin。%uA0字符复制到dst子数组的起始索引dstBegin,并结束于索引:dstbegin + (srcEnd-srcBegin) - 1
声明
以下是java.lang.StringBuilder.getChars()方法的声明
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
参数
-
srcBegin%uA0-- 这表示开始复制这个偏移量。
-
srcEnd%uA0-- 这表示结束复制这个偏移量。
-
dst%uA0-- 这是将数据复制到数组中。
-
dstBegin%uA0-- 这是偏移到dst。
返回值
此方法不返回任何值。
异常
-
NullPointerException%uA0-- 如果%uA0dst 为%uA0null.
-
IndexOutOfBoundsException%uA0-- 这被抛出,如果以下任一条件为真:
srcBegin is negative dstBegin is negative the srcBegin argument is greater than the srcEnd argument. srcEnd is greater than this.length(). dstBegin + srcEnd - srcBegin is greater than dst.length
例子
下面的例子显示java.lang.StringBuilder.getChars()方法的使用。
package com.yiibai import java.lang.* public class StringBuilderDemo { public static void main(String[] args) { StringBuilder str = new StringBuilder("java programming") System.out.println("string = " + str) // char array char[] cArr = new char[]{&apost&apos,&aposu&apos,&apost&apos,&aposo&apos,&aposr&apos,&aposi&apos,&aposa&apos,&aposl&apos,&aposs&apos} // copy the chars from index 5 to index 10 into subarray of cArr // the offset into destination subarray is set to 3 str.getChars(5, 10, cArr, 3) // print character array System.out.println(cArr) } }
让我们来编译和运行上面的程序,这将产生以下结果:
string = java programming tutprogrs