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();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.