Posted on 2011-03-13 17:16
leekiang 阅读(204)
评论(0) 编辑 收藏 所属分类:
java
String s1="ab";
String s2="a"+"b";
System.out.println(s1==s2);//true
String s1 = "abc";
String s2 = "ab";
String s3 = s2 + "c";
System.out.println((s1 == s3));//false
String s1 = "abc";
final String s2 = "ab";
String s3 = s2 + "c";
System.out.println((s1 == s3));//true
参考:
理解Java常量池Java String对象的经典问题(new String())Java堆.栈和常量池 笔记java编译器对string常量表达式的处理和优化Java 程序内存分析