Easy Tutorial
❮ Java Object Getclass Arrays Fill ❯

Java getChars() Method

Java 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

This method does not return a value but throws an IndexOutOfBoundsException.

Example

public class Test {
    public static void main(String args[]) {
        String Str1 = new String("www.tutorialpro.org");
        char[] Str2 = new char[6];

        try {
            Str1.getChars(4, 10, Str2, 0);
            System.out.print("Copied String is: ");
            System.out.println(Str2);
        } catch(Exception ex) {
            System.out.println("Exception occurred...");
        }
    }
}

The output of the above program is:

Copied String is: tutorialpro

Java String Class

❮ Java Object Getclass Arrays Fill ❯