What is the reason?
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
ThomasLC
22 May 2019, 17:09
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