Java 字符串 getChars() 方法
示例
将字符串的一部分复制到char数组中:
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);
定义和用法
getChars() 方法将字符串中的字符复制到 char 数组中。
语法
public void getChars(int start, int end, char[] destination, int position)
参数值
| 参数 | 描述 |
|---|---|
| start | 必需。要复制的第一个字符在字符串中的位置。 |
| end | 必需。要复制的最后一个字符在字符串中的位置。 |
| destination | 必需。要将字符复制到的数组。 |
| position | 必需。复制的字符在目标数组中的位置。 |
技术细节
| 返回值: | 无 |
|---|---|
| 抛出异常: | IndexOutOfBoundsException - 在以下任何情况下:
|
| Java 版本: | 任意 |
❮ String 字符串方法

