一个String代码,便于深入理解String

来源:互联网 发布:js slibing 编辑:程序博客网 时间:2024/05/21 11:20
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
原创粉丝点击