Possible Duplicate:
What is the purpose of the expression “new String(…)” in Java?
It's immutable, why would you need to invoke String.String(String str) ?
From the API doc:
Unless an explicit copy of original is needed, use of this constructor is
unnecessary since Strings are immutable.
The only reason I can think of is in the situation where:
String: A.substring you'll see it references the same char[] array as the original string.String A has gone out of scope and you wish to reduce memory consumption.char[]. Allowing B to go out of scope will allow the garbage collector to reclaim the large char[] that backs A and B, leaving only the small char[] backing B'.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