Wrong output when comparing using arrayList.get()


#1

while comparing like if( a.get(i) != b.get(j))

for input [1, 1, 1], output is [1]
for input [5000, 5000, 5000], output is [5000, 5000, 5000]

if stored in int variable first and then compared, i.e.,
int first = a.get(i);
int second = b.get(j);
if(first != second)

output is fine.
why that happens??