void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
描述 (Description)
java.lang.StringBuffer.getChars()方法将此序列中的字符复制到目标字符数组dst 。 要复制的第一个字符是索引srcBegin 。 要复制的最后一个字符是索引srcEnd - 1 。 要复制的字符总数是srcEnd - srcBegin 。 字符被复制到dst的子dstBegin ,从索引dstBegin开始,到索引结束: dstbegin + (srcEnd-srcBegin) - 1
声明 (Declaration)
以下是java.lang.StringBuffer.getChars()方法的声明
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
参数 (Parameters)
srcBegin - 开始复制此偏移量。
srcEnd - 停止复制此偏移量。
dst - 这是将数据复制到的数组。
dstBegin - 这是dst的偏移量。
返回值 (Return Value)
此方法不返回任何值。
异常 (Exception)
NullPointerException - 如果dst为null
IndexOutOfBoundsException - 如果满足以下任何条件,则抛出此异常 -
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
例子 (Example)
以下示例显示了java.lang.StringBuffer.getChars()方法的用法。
package com.iowiki;
import java.lang.*;
public class StringBufferDemo {
public static void main(String[] args) {
StringBuffer buff = new StringBuffer("java programming");
System.out.println("buffer = " + buff);
// char array
char[] chArr = new char[]{'t','u','t','o','r','i','a','l','s'};
// copy the chars from index 5 to index 10 into subarray of chArr
// the offset into destination subarray is set to 3
buff.getChars(5, 10, chArr, 3);
// print character array
System.out.println(chArr);
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
buffer = java programming
tutprogrs