The output for following print statement is same, is there any internal difference which is safe as per Privacy Violation: Heap Inspection
char[] ch ={'p','a','s','s','w','o','r','d'};
System.out.println(String.valueOf(ch));
System.out.println(new String(ch));
There is no real difference because internal implementation of valueOf is the following:
public static String valueOf(char data[]) {
return new String(data);
}
As you can see it calls directly new String(data)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With