new String 2005-10-17 - By Sonali Kansara
Back
Yes Frans is right ......... its a concept called interned strings ...........
In case of compile time constant strings , a string available from the pool is utilized instead of creating a new instance of the string .
So
String s1 = "Test5" ; String s2 = "Test5" ; String s3 = "Test"+"5" ;
int i = 5 ; String s4 = "Test"+i ;
Here s1 , s2 , s3 are refering to the same instance of Test5 while s4 creates a new instance .
Regards , Sonali
Notice: The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you
=========================================================================== To unsubscribe, send email to listserv@(protected) and include in the body of the message "signoff J2EE-INTEREST". For general help, send email to listserv@(protected) and include in the body of the message "help".
<br><font size=2 face="sans-serif">Yes Frans is right ......... its a concept called interned strings ...........</font> <br> <br><font size=2 face="sans-serif">In case of compile time constant strings , a string available from the pool is utilized instead of creating a new instance of the string .</font> <br> <br><font size=2 face="sans-serif">So </font> <br> <br><font size=2 face="sans-serif">String s1 = "Test5" ;</font> <br><font size=2 face="sans-serif">String s2 = "Test5" ; </font> <br><font size=2 face="sans-serif">String s3 = "Test"+"5" ; </font> <br> <br><font size=2 face="sans-serif">int i = 5 ;</font> <br><font size=2 face="sans-serif">String s4 = "Test"+i ;</font> <br> <br><font size=2 face="sans-serif">Here s1 , s2 , s3 are refering to the same instance of Test5 while s4 creates a new instance .</font> <br> <br> <br><font size=2 face="sans-serif">Regards , </font> <br><font size=2 face="sans-serif">Sonali </font> <br> <table><tr><td bgcolor=#ffffff><font color=#000000>Notice: The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient , any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you<br> </font></td></tr></table> =========================================================================== To unsubscribe, send email to listserv@(protected) and include in the body of the message "signoff J2EE-INTEREST". For general help, send email to listserv@(protected) and include in the body of the message "help". <p>
|
|