public void test(){
String s1 = "ab" + "c";
String s2 = "abc";
System.out.println(s1 == s2 + ":" +s1.equals(s2));
}
so easy 么 ?你试试
public static void main(String[] args) {
String a = new String("abcd");
String b = new String("abcd");
String c = "abcd" + "ppp";
String d = "abcd";
String e = "abcd" + "ppp";
String f = d + "ppp";
System.out.println((a == b) + "-------------" + a.equals(b));
System.out.println((a == d) + "-------------" + a.equals(d));
System.out.println((b == d) + "-------------" + b.equals(d));
System.out.println((c == e) + "-------------" + c.equals(e));
System.out.println((f == e) + "-------------" + f.equals(e));
a = a.intern();
System.out.println((a == d) + "-------------" + a.equals(d));
}
false-------------true
false-------------true
false-------------true
true-------------true
false-------------true
true-------------true
是不是已经疯了?