The program prints out sth like
j1=0j2=0 7698380----7698380
the difference is 0
j1=0j2=1 7698380----7726365
the difference is -27985
j1=1j2=0 7726365----7698380
the difference is 27985
j1=1j2=1 7726365----7726365
the difference is 0
j1=0j2=0 7698380----7698380
the difference is 0

Even the two values, temp1.get(j1) and temp2.get(j2) do overlap, the "if" part just did not go through.

If I change the

if (temp1.get(j1)==temp2.get(j2))

to

if (xyz == 0)

The result will look like
j1=0j2=0 7698380----7698380
the difference is 0
find match
j1=0j2=1 7698380----7726365
the difference is -27985
j1=1j2=0 7726365----7698380
the difference is 27985
j1=1j2=1 7726365----7726365
the difference is 0
find match
j1=0j2=0 7698380----7698380
the difference is 0
find match

The result is just what I expected. Can you let me know how does this happen? Thanks a lot.

Can I assume that .equals() should be an robust approach to avoid these uncertainties? Thanks.

Have a look at the documentation for Integer. It says

public boolean equals(Object obj)
Compares this object to the specified object. The result is true if and only if the argument is not null and is an Integer object that contains the same int value as this object.

I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...

Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...