java.lang.StringBuffer.getChars()%uA0方法从这个序列复制字符到目标字符数组%uA0dst.
要复制的第一个字符的索引%uA0srcBegin. 要复制的最后一个字符位于索引srcEnd - 1. 要复制字符的总数是%uA0srcEnd - srcBegin.%uA0字符复制到dst开始于索引dstBegin并结束于索引子数组:%uA0dstbegin + (srcEnd-srcBegin) - 1
声明
以下是java.lang.StringBuffer.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.StringBuffer.getChars()方法的使用。
package com.yiibai 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[]{&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 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