1 / 2
May 2020

Because you’re comparing objects, not their values, and num3 and num4 are different objects. (100 works as expected for num1 and num2 because of Java’s special treatment and caching of Integers between -128 and 127.)

Bottom line is you should be comparing using .equals for objects such as Integers, and reserve == and != for primitives.

See this3 and this.