前言
定义和用法copyValueOf() 方法返回表示 char 数组中字符的 String。此方法返回新的 String 数组,并将字符复制到其中。实例返回表示
定义和用法
copyValueOf() 方法返回表示 char 数组中字符的 String。
此方法返回新的 String 数组,并将字符复制到其中。
实例
返回表示 char 数组中某些字符的字符串:
char[] myStr1 = {'H', 'e', 'l', 'l', 'o'};
String myStr2 = "";
myStr2 = myStr2.copyValueOf(myStr1, 0, 5);
System.out.println("Returned String: " + myStr2);
运行实例 »
点击 "运行实例" 按钮查看在线实例
语法
public static String copyValueOf(char[] data, int offset, int count)
运行实例 »
点击 "运行实例" 按钮查看在线实例
参数
| 参数 | 描述 |
|---|---|
| data |
char 数组。 |
| offset |
int 值,表示 char 数组的起始索引。 |
| count |
int 值,表示 char 数组的长度。 |
技术细节
| 返回: | |
|---|---|
| 抛出: |
StringIndexOutOfBoundsException:
如果 offset 为负数或超出范围
或者 count 大于 char 数组的长度
或者为负数
|
