Java copyValueOf () method
There are two forms copyValueOf () method:
public static String copyValueOf (char [] data): Returns a string array of the sequence of characters represented.
public static String copyValueOf (char [] data, int offset, int count): Returns a string array of the sequence of characters represented.
grammar
public static String copyValueOf(char[] data) 或 public static String copyValueOf(char[] data, int offset, int count)
parameter
data - the character array.
offset - the initial offset of the subarray..
count - the length of the sub-array.
return value
Such as a string with the specified StringBuffer represent the same sequence of characters, it returns true; otherwise false.
Examples
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); } }
The above program execution results:
返回结果:hello w3big 返回结果:llo ru