Java StringBuilder getChars() Method
Example
Copy the word "World" into a char array:
StringBuilder sb = new StringBuilder("Hello World");
char[] letters = new char[5];
sb.getChars(6, 11, letters, 0);
System.out.println(letters);
Definition and Usage
The getChars() method copies characters from a StringBuilder into a char array.
Syntax
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
Parameter Values
| Parameter | Description |
|---|---|
| srcBegin | Required. The index of the first character to copy. |
| srcEnd | Required. The index after the last character to copy. |
| dst | Required. The char array to copy the characters into. |
| dstBegin | Required. The position in the array where the first character is placed. |
Technical Details
| Throws: | IndexOutOfBoundsException - if any of the positions are outside the text or the array. |
|---|
Related Pages
❮ StringBuilder Methods