[ajug-members] creating strings

ashish butani abutani at hotmail.com
Sun Jul 22 13:16:27 EDT 2007


 
I think Strings are pooled by JVM for improving efficiency. By explicitly creating objects using the new operator you are indicating to the JVM to not use it from the pool.
 
For example if you have something like this
 
String a = "xyz";
String b = "xyz";
String c = new String("xyz");
 
In the above case, a new object is created for a and c but not for b. This is because b references to the same literal as a (i.e xyz).
 
Thanks
Ashish Butani
 
 



> Date: Sat, 21 Jul 2007 22:54:34 -0400> From: sony.antony at gmail.com> To: ajug-members at ajug.org> Subject: [ajug-members] creating strings> > Is there any different between teh following string instantiations at> run time ( memory, speed of execution etc. )> > String s = new String( "XXX") ;> > String s = "XXX" ;> > > I thought they are both exactly same as new strings are created only> if there isn't already an entry in the string table for the same> string.> > > --sony> _______________________________________________> ajug-members mailing list> ajug-members at ajug.org> http://www.ajug.org/mailman/listinfo/ajug-members
_________________________________________________________________
See what you’re getting into…before you go there.
http://newlivehotmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.ajug.org/pipermail/ajug-members/attachments/20070722/753c6805/attachment.html 


More information about the ajug-members mailing list