Possible Duplicate:
What is the purpose of the expression “new String(…)” in Java?
I know that String s = new String("Hello World")
should be avoided as it will create extra space for "Hello World" which is unnecessary in most cases.
Related question explaining why String s = new String("Hello World")
should be avoided is here:
What is the difference between "text" and new String("text")?
But when do we need to use String s = new String("Hello World")
, instead of String s = "Hello World"
? This is a interview question I experienced.
If String s = new String("Hello World")
should be avoided in most cases, why Java still allows that?