public class StringTest {
/**
* @param args
*/
public static void main(String[] args) {
String str1 = "abc";
String str2 ="de";
String str3 = str1 + str2;
String str4 ="abc" + "de";
String str5="abcde";
System.out.println(str3==str5);
System.out.println(str4==str5);
}
}
以前搞不懂到低是true或false,呵呵,现在借助javap,一看就明了。
public static void main(java.lang.String[]);
Code:
0: ldc #2; //String abc
2: astore_1
3: ldc #3; //String de
5: astore_2
6: new #4; //class java/lang/StringBuilder
9: dup
10: invokespecial #5; //Method java/lang/StringBuilder."<init>":()V
13: aload_1
14: invokevirtual #6; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
17: aload_2
18: invokevirtual #6; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
21: invokevirtual #7; //Method java/lang/StringBuilder.toString:()Ljava/lang/String;
24: astore_3
25: ldc #8; //String abcde
27: astore 4
29: ldc #8; //String abcde
31: astore 5
33: getstatic #9; //Field java/lang/System.out:Ljava/io/PrintStream;
36: aload_3
37: aload 5
39: if_acmpne 46
42: iconst_1
43: goto 47
46: iconst_0
47: invokevirtual #10; //Method java/io/PrintStream.println:(Z)V
50: getstatic #9; //Field java/lang/System.out:Ljava/io/PrintStream;
53: aload 4
55: aload 5
57: if_acmpne 64
60: iconst_1
61: goto 65
64: iconst_0
65: invokevirtual #10; //Method java/io/PrintStream.println:(Z)V
68: return
}