the "= =" Comparison is the address, remember.
1. Object. Integer is an object
Integer I1 = 20;integer i2 = 20; System.out.println (I1 = = I2); Trueinteger i3 = 200;integer I4 = 200; System.out.println (i3 = = I4); False
Reason: Integer i1 = 20; is actually an automatic boxing process, the compiler will automatically expand into an Integer i = integer.valueof (20); details can be seen integer.valueof source code, you can see the value of the parameter in Integercache.low (Default-128) to Integercache.high (the default 127) in the range (such as 20), will be directly from the Integercache.cache (refer to the source code of the internal class integercache of the integer, if not configured, The default is the cache store-128 to 127 integer), so the same integer is taken to the same object, so the same. And 200 is not in the range 128 to 127, so it will be new integer, so it is not the same. 2. Type. int is the basic data type
int I1=20;int i2=20; System.out.println (I1==I2);//trueint i3=200;int i4=200; System.err.println (I3==I4);//true
Reason: I1 opened up a memory space, for I2, the JVM first in memory to find whether there is 20 address, there is to assign value to I2, that is, let I2 also point to 20 that block address. So the return is true.
3.
String str1 = "Hello"; String str2 = "he" + New String ("Llo"); System.err.println (str1 = = str2);
The return is false.
Cause: because the Llo in STR2 is a new block of memory, and = = Determines the address of the object instead of the value, it is not the same. If it is string str2 = str1, then it is true.
Java object and basic data type "= =" Difference