Java String copyValueOf() 方法
定义和用法
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:
|