Java: valueOf vs copyValueOf

What is the difference between valueOfand copyValueOf. I looked at GrepCode, only to find that both return the same.

copyValueOf:

Parameters : data - an array of characters.

Returns : A string containing the characters of an array of characters.

public static String copyValueOf (char data []) {return new String (data); }

valueOf:

Returns a string representation of the argument of the char array. The contents of the character array are copied; subsequent modification of the character array does not affect the returned string.

Parameters : character array data.

Returns : A string containing the characters of an array of characters.

public static String valueOf (char data []) {return new String (data); }

So, if both do the same thing, then why is one not obsolete?

+4
3

:

  • .
  • javadocs , . copyValueOf () valueOf.
  • . .
  • , "" , . () , .
  • ... . .

, "". , , , API-, . , Java ... , -- API " ", .. (Most , Java . , Java, .)

-, , ( ) . Oracle... (@StarCoder) , .

+2

, @Deprecated, , , , , , , . , ( ).

; . , , .

+1

, ( String.java - ):

copyValueOf (char data []): , . .

valueOf (char data []): , . String (.. ).

redudndency . java . , , , .

+1

Source: https://habr.com/ru/post/1691836/