Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Java getChars() Method

Java getChars() Method

Java String ClassJava String class


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

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 ClassJava String class