Java copyValueOf() 方法
copyValueOf() 方法有兩種形式:
public static String copyValueOf(char[] data):返回指定數組中表示該字符序列的字符串。
public static String copyValueOf(char[] data, int offset, int count):返回指定數組中表示該字符序列的字符串。
語法
public static String copyValueOf(char[] data) 或 public static String copyValueOf(char[] data, int offset, int count)
參數
data --字符數組。
offset --子數組的初始偏移量。。
count --子數組的長度。
返回值
如字符串與指定StringBuffer 表示相同的字符序列,則返回true;否則返回false。
實例
public class Test { public static void main(String args[]) { char[] Str1 = {'h', 'e', 'l', 'l', 'o', ' ', 'r', 'u', 'n', 'o', 'o', 'b'}; String Str2 = ""; Str2 = Str2.copyValueOf( Str1 ); System.out.println("返回结果:" + Str2); Str2 = Str2.copyValueOf( Str1, 2, 6 ); System.out.println("返回结果:" + Str2); } }
以上程序執行結果為:
返回结果:hello w3big 返回结果:llo ru