Originally posted by Asuthosh Borikar:
To summarize,
String sString = new String("blahblah");
String tString = new String("blahblah");
will ALWAYS result in two new objects.
But,
String sString = "blahblah";
String tString = "blahblah";
will only result in one new object.
Actually,
String sString = new String("blahblah");
String tString = new String("blahblah");
could potentially result in not TWO but THREE new objects. The first object is the string literal "blahblah" which, as you pointed out, will exist in the pool of literal strings after this call is made. The other two are the new Strings that are explicitly created.
(reference: RHE 2nd ed. p. 257)
Either way, to the original question,
String sString = new String("blahblah");
is very wasteful.
--
Susan
[This message has been edited by Susan Hoover (edited January 30, 2001).]