目录

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

描述 (Description)

java.lang.StringBuilder.getChars()方法将此序列中的字符复制到目标字符数组dst

要复制的第一个字符是索引srcBegin ; 要复制的最后一个字符是索引srcEnd - 1 。 要复制的字符总数是srcEnd - srcBegin 。 字符被复制到dst的子dstBegin ,从索引dstBegin开始,到索引结束: dstbegin + (srcEnd-srcBegin) - 1

声明 (Declaration)

以下是java.lang.StringBuilder.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.StringBuilder.getChars()方法的用法。

package com.iowiki;
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[]{'t','u','t','o','r','i','a','l','s'};
      // 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
↑回到顶部↑
WIKI教程 @2018