Wrong output with debug statement

For an array input of [5000, 5000, 5000], I put in a debug statement in my code as follows

System.out.print(a.get(i) + " " + a.get(i - 1) + " ");
System.out.println((a.get(i) == a.get(i - 1)));

For i = 1, I expected “5000 5000 true” but instead I get “5000 5000 false”.

What am I not getting right?

For checking equality for Objects (like Integers), you should use the method equals(). == checks equality for primitive data types like int and object equality.

Click here to start solving coding interview questions