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.
+1
This website uses cookies to provide you with personalized service. By using this website, you agree to our use of cookies. If you require more details, please read our Terms and Policy.