String s = new String("1") + new String("1");
String s2 = s + "1" + "1" + "1";
//String s = "1" + "1";
String s1 = "11";
System.out.println(s.intern() == s1);
public static void main(java.lang.String[] args);
0 new java.lang.StringBuilder [16]
3 dup
4 new java.lang.String [18]
7 dup
8 ldc <String "1"> [20]
10 invokespecial java.lang.String(java.lang.String) [22]
13 invokestatic java.lang.String.valueOf(java.lang.Object) : java.lang.String [25]
16 invokespecial java.lang.StringBuilder(java.lang.String) [29]
19 new java.lang.String [18]
22 dup
23 ldc <String "1"> [20]
25 invokespecial java.lang.String(java.lang.String) [22]
28 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [30]
31 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [34]
34 astore_1 [s]
35 new java.lang.StringBuilder [16]
38 dup
39 aload_1 [s]
40 invokestatic java.lang.String.valueOf(java.lang.Object) : java.lang.String [25]
43 invokespecial java.lang.StringBuilder(java.lang.String) [29]
46 ldc <String "1"> [20]
48 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [30]
51 ldc <String "1"> [20]
53 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [30]
56 ldc <String "1"> [20]
58 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [30]
61 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [34]
64 astore_2 [s2]
65 ldc <String "11"> [38]
67 astore_3 [s1]
68 getstatic java.lang.System.out : java.io.PrintStream [40]
71 aload_1 [s]
72 invokevirtual java.lang.String.intern() : java.lang.String [46]
75 aload_3 [s1]
76 if_acmpne 83
79 iconst_1
80 goto 84
83 iconst_0
84 invokevirtual java.io.PrintStream.println(boolean) : void [49]
87 return
Line numbers:
[pc: 0, line: 18]
[pc: 35, line: 19]
[pc: 65, line: 21]
[pc: 68, line: 22]
[pc: 87, line: 23]
Local variable table:
[pc: 0, pc: 88] local: args index: 0 type: java.lang.String[]
[pc: 35, pc: 88] local: s index: 1 type: java.lang.String
[pc: 65, pc: 88] local: s2 index: 2 type: java.lang.String
[pc: 68, pc: 88] local: s1 index: 3 type: java.lang.String
Stack map table: number of frames 2
[pc: 83, full, stack: {java.io.PrintStream}, locals: {java.lang.String[], java.lang.String, java.lang.String, java.lang.String}]
[pc: 84, full, stack: {java.io.PrintStream, int}, locals: {java.lang.String[], java.lang.String, java.lang.String, java.lang.String}]
}
从class文件中可以看出,依然new了两个stringBuilder对象