Java getChars() Method
The getChars() method copies characters from the string into the destination character array.
Syntax
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
Parameters
-
srcBegin -- The index of the first character in the string to copy.
-
srcEnd -- The index after the last character in the string to copy.
-
dst -- The destination array.
-
dstBegin -- The starting offset in the destination array.
Return Value
Has no return value, but throws an IndexOutOfBoundsException.
Example
public class Test {
public static void main(String args[]) {
String Str1 = new String("www.runoob.com");
char[] Str2 = new char[6];
try {
Str1.getChars(4, 10, Str2, 0);
System.out.print("拷贝的字符串为:" );
System.out.println(Str2 );
} catch( Exception ex) {
System.out.println("触发异常...");
}
}
}
The execution result of the above program is:
拷贝的字符串为:runoob
Java String class