public class Test2 {
public static void main(String[] args) {
String str1=new String("hello");
String str2=new String("hello");
System.out.println(str1==str2?0:1);
String str3="hello";
String str4="hello";
System.out.println(str3==str4?0:1);
Integer a=127;
Integer b=127;
System.out.println(a==b?0:1);
Integer c=129;
Integer d=129;
System.out.println(c==d?0:1);
}
}
结果为:1 0 0 1
注:Integer 类型的值在[-128,127] 期间,Integer 用 “==”是判断的为值;超出范围则为对象,按对象进行比较。