java.lang.String.getChars()%uA0方法复制此字串到目标字符数组的字符。
要复制的第一个字符的索引srcBegin, 要复制的最后一个字符位于索引%uA0srcEnd-1%uA0即要复制的字符的总数目是%uA0srcEnd-srcBegin。
字符复制到dst 开始于索引dstBegin并结束于索引子数组:dstbegin + (srcEnd-srcBegin) - 1
声明
以下是java.lang.String.getChars()方法的声明
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
参数
-
srcBegin%uA0-- 这是复制的字符串的第一个字符的索引。
-
srcEnd%uA0-- 这是复制字符串中的最后一个字符之后的索引。
-
dst%uA0-- 这是目标数组。
-
dstBegin%uA0-- 这是一开始的目标数组中的偏移量。
返回值
此方法不返回任何值。
异常
-
IndexOutOfBoundsException%uA0-- 它抛出这个异常,如果任一下列条件为真:
srcBegin is negative srcBegin is greater than srcEnd srcEnd is greater than the length of this string dstBegin is negative dstBegin+(srcEnd-srcBegin) is larger than dst.length
例子
下面的例子显示java.lang.String.getChars()方法的使用。
package com.yiibai import java.lang.* public class StringDemo { public static void main(String[] args) { String str = "Website:www.yiibai.com" System.out.println(str) // character array char[] chararr = new char[30] /* copies characters from starting and ending index into the destination character array */ str.getChars(12, 26, chararr, 0) // print the character array System.out.print("Value of character array : ") System.out.println(chararr) } }
让我们来编译和运行上面的程序,这将产生以下结果:
Website:www.yiibai.com Value of character array : yiibai