Here is my code:
String s = new String("1"); // here I know that "1" is created in const pool
String s2 = new String("1") + new String("1");
Does "11" created in the String pool immediately in this code? If not, should I invoke s2.intern()
to put "11" to String pool?
--------------udapte 22/9/2016---------------------
Here I have somethings confuse me: Both new Stirng("1") and new String("1") + new String("1") invoke the same native method System.arraycopy which I learn from JDK6.
Now why does "1" will be created in String pool but "11" does't? Does anything make differences in StringBuilder? Maybe method "append" or ...?
I will be appreciated for your assistance.