java 字符串奇怪问题
环境 :jdk1.8 系统:mac
当字符串在10~12的时候都是false,在09以下或13以上都是true,不知道是什么原因导致的?
public static void test3() {
String s = new String("1")+new String("0");
s.intern();
String s1 = "10";
System.out.println(s == s1); //false
}
public static void test3() {
String s = new String("1")+new String("1");
s.intern();
String s1 = "11";
System.out.println(s == s1); //false
}
public static void test3() {
String s = new String("1")+new String("2");
s.intern();
String s1 = "12";
System.out.println(s == s1); //false
}
public static void test3() {
String s = new String("1")+new String("3");
s.intern();
String s1 = "13";
System.out.println(s == s1); //true
}
public static void test3() {
String s = new String("0")+new String("9");
s.intern();
String s1 = "09";
System.out.println(s == s1); //true
}