== 用于比较两个对象的引用是否相同,equals()重写了object类的equals(),比较的是两个对象的实际内容是否相同。
注意:包装类的==不遇到算术运算的情况下不会自动拆箱,以及它们的equals()方法不处理数据转型的关系。
public static void main(String[] args){
Integer a = 1;
Integer b = 2;
Integer c = 3;
Integer d = 3;
Integer e = 321;
Integer f = 321;
Long g = 3L;
System.out.println( c == d);//true
System.out.println(e == f);//false
System.out.println(c == (a+b));//true
System.out.println(c.equals(a+b));//ture
System.out.println(g == (a+b));//true
System.out.println(g.equals(a+b));//false
}
想了解Integer的自动拆箱和装箱请转至https://blog.csdn.net/weixin_43183405/article/details/104662614