Java getChars() Method
The getChars() method copies characters from a string into a 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 be copied.
srcEnd-- The index after the last character in the string to be copied.
dst-- The destination array.
dstBegin-- The starting offset in the destination array.
Return Value
No return value, but throws IndexOutOfBoundsException.
Example
public class Test {
public static void main(String args[]) {
String Str1 = new String("www.example.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 output of the above program is:
拷贝的字符串为:example
Other Extensions
Java String Class