Since Strings are immutable in Java, why would I want to use the argument-less String constructor and create an object?
How is the variable s
useful to me after I do:
String s = new String();
new String()
is an empty string. This could be a return value from a method, for example, if you don't have anything more interesting to return. Using the literal ""
is probably better because the literal empty string value will already be interned.
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