Here i wrote simple java code.
Integer Example
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
}
}
Integer [ ] Example
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 ?
}
}
For the Integer it returns both true and that is ok. But i can not understand For Integer[ ] how it return both false. thanks in advance.