Okay this is way advance, but I'll try to explain.
int = primitive data type, stores actual binary value (i.e. "==" compares actual binary value)
Integer = it's a class and keeps a cache of Integer instances in the range of -128 to 127 (meaning between these numbers it compares the actual value and its true, outside these values it's comparing references which "==" will not be sufficient)
in the first example, if you changed "==" to ".equals()" it will work as well.