Java String getChars() Method
Example
Copy part of a string into a char
array:
char[] myArray = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
System.out.println(myArray);
String myStr = "Hello, World!";
myStr.getChars(7, 12, myArray, 4);
System.out.println(myArray);
Definition and Usage
The getChars()
method copies characters from a string to a char
array.
Syntax
public void getChars(int start, int end, char[] destination, int position)
Parameter Values
Parameter | Description |
---|---|
start | Required. The position in the string of the first character to be copied. |
end | Required. The position in the string after the last character to be copied. |
destination | Required. The array to which the characters are copied. |
position | Required. The position in the destination array to which the copied characters are written. |
Technical Details
Returns: | None |
---|---|
Throws: | IndexOutOfBoundsException - In any of these conditions:
|
Java version: | Any |
❮ String Methods