Possible Duplicate:
Questions about Java's String pool
Recently I read a java article and found the following statement "improved the String pooling technology in java 6 onward". One of the example that they have mentioned as follows
String one = "one";
String two = new String("one");
Number of objects created by above example is = 1
Here I am little confused, even though we are using the new
keyword how come it will not create a new object and uses the object created in the string pool.
Please clarify me.
I think doing one == two should help determining how many objects got created.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With