一個String代碼,便於深入理解String

class X
{
public String strX="hello";
}
class Y
{
public String strY= new String("hello");
}
class Z
{
public String strZ="hell"+"o";
}
public class TestString
{
public static void main(String[] args)
{
X x=new X();
Y y=new Y();
Z z=new Z();
System.out.println( x.strX==y.strY);
System.out.println( x.strX==z.strZ);
String s1="hel";
String s2="lo";
System.out.println( x.strX==(s1+s2));
System.out.println( x.strX==(s1+s2).intern());
}
}
輸出:
false
true
false
true
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章