What is the difference between valueOf
and copyValueOf
. I looked on GrepCode, only to find that both return the exact same thing.
copyValueOf:
Parameters: data the character array.
Returns: a String that contains the characters of the character array.
public static String copyValueOf(char data[]) { return new String(data); }
valueOf:
Returns the string representation of the char array argument. The contents of the character array are copied; subsequent modification of the character array does not affect the returned string.
Parameters: data the character array.
Returns: a String that contains the characters of the character array.
public static String valueOf(char data[]) { return new String(data); }
So if both do the same thing, then how come one isn't deprecated?
copyValueOf
. And if they do it probably would be an old program, they won't use Java 8+. – LaughvalueOf
is the function that lost its original intent, and was never a replacement forcopyValueOf
. I suppose neither will ever be removed and there's no strong reason to use one over the other. – Sulfur