这里我写了简单的java代码。
整数示例
class Question {
public static void main(String[] args) {
Integer arr1 = 1;
Integer arr2 = 1;
System.out.println("arr1 == arr2 is " + (arr1 == arr2));//this check object reference - this returns true
System.out.println("arr1.equals(arr2) is " + arr1.equals(arr2));// this check value - this also return true
}
}
整数[]示例
class Question {
public static void main(String[] args) {
Integer[] arr1 = {1, 2, 3, 4, 5};
Integer[] arr2 = {1, 2, 3, 4, 5};
System.out.println("arr1 == arr2 is " + (arr1 == arr2));// i know this check object reference - but this return false -how it happen ?
System.out.println("arr1.equals(arr2) is " + arr1.equals(arr2));// i know this check value - but this also return false -how it happen ?
}
}
对于Integer,它返回true,即可。 但是我无法理解For Integer []它如何返回false。 提前谢谢。