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 - 如果偏移量為負數或超出範圍,或者如果 count 大於字元陣列的長度,或者為負數 |
❮ String Methods