The following codes has different results under JDK8 1.8.0_171
@Test
public void test2() {
String s1 = new String("a") + new String("a");
s1.intern();
String s2 = "aa";
System.out.println(s1 == s2); //true
}
@Test
public void test3() {
String s1 = new String("1") + new String("1");
s1.intern();
String s2 = "11";
System.out.println(s1 == s2); //false
}
The only difference is the value: "a" instead of "1", the result I get is different. Why is this?