String s1="ab"; String s2="a"+"b"; //被編譯器優化爲 "ab" String s3="a"; String s4="b"; String s5=s3+s4; //被建立在堆裏面 System.out.println(s5==s2); //false
String s1=」aa」; String s2=s1.intern(); System.out.print(s1==s2);//返回true優化