In java String can be created by using new operator or by using + and +=. So, does all these string creation techniques check whether the string already exist in the string pool. If they dint then which String creation technique will check the pool.
Share
No they don’t.
Simple example :
This code on ideone
Here the new version of “s” isn’t the internal version of “hello”
If you want to have the pool version of a specific string, you can use the
intern()method (just as I did above). This way you’re sure to have the same reference.Resources :
String.intern()(you might think that the link points tovalueOf(double), but theintern()method is right after 😉 )