Public classtest{ Public Static voidMain (string[] args) {Integer i1= 100; Integer i2= 100;if(I1 = =I2) {System.out.println ("I1==i2");}Else{System.out.println ("I1! = i2");}}} Public classtest1{ Public Static voidMain (string[] args) {Integer i1= 200; Integer i2= 200;if(I1 = =I2) {System.out.println ("I1==i2");}Else{System.out.println ("I1! = i2");}}}
The test found that the first data output I1==I2, the second data output i1!=i2.
The reason is because
When assigning a value to an integer, it is actually an auto-boxing process, which is called the integer.valueof (int) method, which uses a constant pool when the value is greater than or equal to 128 and less than or equal to 127, so the first two addresses are equal, but the last two are more than 127, Therefore, a constant pool is not used.
Other words
Integer-128~127 actually you can think of as an int, so the output of the first class should be = =
Interger more than 128 of the value can not be regarded as int, he is the object, two different values of the same object if it is determined to be unequal, can be judged by equals.
Size comparison of integer and integer data