Java String copyValueOf() 方法
实例
返回表示字符数组中某些字符的字符串:
char[] myStr1 = {'H', 'e', 'l', 'l', 'o'};
String myStr2 = "";
myStr2 = myStr2.copyValueOf(myStr1, 0, 5);
System.out.println("Returned String: " + myStr2);
定义和用法
copyValueOf() 方法返回表示字符数组字符的 String 字符串。
此方法返回一个新的 String 字符串数组并将字符复制到其中。
语法
public static String copyValueOf(char[] data, int offset, int count)
参数值
| 参数 | 描述 |
|---|---|
| data | char 数组 |
| offset | int 值, 表示字符数组的开始索引 |
| count | int 值, 表示字符数组的长度 |
技术细节
| 返回值: | String, 表示字符数组的字符 |
|---|---|
| 抛出异常: | StringIndexOutOfBoundsException - 如果偏移量为负数或超出范围,或者如果计数大于字符数组的长度,或者为负数 |
❮ Java 字符串方法

