I have 2 questions about arrays in Java, hope you can save your time to help me.
Question 1:
int[] intArray1 = { 1, 4, 2, 5, 6, 7, 2 };
int[] intArray2 = { 1, 4, 2, 5, 6, 7, 2 };
intArray1.equals(intArray2);
But does it return false?
Question 2:
I run this code:
int[] intArray1 = { 1, 4, 2, 5, 6, 7, 2 };
Arrays.binarySearch(intArray1,2);
and it returns -2.
BUT, when I remove the duplication:
int[] intArray3 = { 1, 4, 2, 5, 6, 7};
Arrays.binarySearch(intArray1,2);
now it returns 2, which is correct.
I don’t know how binary search in an array deals with duplication, which leads to -2?