![]() |
VOOZH | about |
The getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) method of StringBuffer class copies the characters starting at the index:srcBegin to index:srcEnd-1 from actual sequence into an array of char passed as parameter to function.
Syntax:
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
Parameters: This method takes four parameters:
Returns: This method returns nothing. Exception: This method throws StringIndexOutOfBoundsException if:
Below programs demonstrate the getChars() method of StringBuffer Class: Example 1:
String = Geeks For Geeks char array contains : . G e e k s F o r . . . . .
Example 2: To demonstrate StringIndexOutOfBoundsException.
Exception: java.lang.StringIndexOutOfBoundsException: srcBegin > srcEnd
References: https://docs.oracle.com/javase/10/docs/api/java/lang/StringBuffer.html#getChars(int, int, char%5B%5D, int)