1. Interview questions:
Integer i = 1;
i + = 1;
What has been done?
(1) where Integer i = 1; automatic boxing (using valueof () method, int---> Integer)
(2) where I +=1; the integer type I is automatically disassembled into int (using the Intvalue () method, Integer--->int), after the completion of the addition run I is then boxed into an integer type.
2. Interview questions:
Observe the following procedure to determine the output to write the result:
1 Packagecn.itcast_06;2 3 /*4 * See program Write results5 * 6 * Note: integer data is directly assigned, if between 128 and 127, the data will be fetched directly from the buffer pool.7 */8 Public classIntegerdemo {9 Public Static voidMain (string[] args) {TenInteger I1 =NewInteger (127); OneInteger i2 =NewInteger (127); ASystem.out.println (I1 = =i2); - System.out.println (I1.equals (I2)); -System.out.println ("-----------"); the -Integer i3 =NewInteger (128); -Integer I4 =NewInteger (128); -System.out.println (i3 = =I4); + System.out.println (I3.equals (I4)); -System.out.println ("-----------"); + AInteger i5 = 128; atInteger I6 = 128; -SYSTEM.OUT.PRINTLN (i5 = =I6); - System.out.println (I5.equals (I6)); -System.out.println ("-----------"); - -Integer i7 = 127; inInteger i8 = 127; -System.out.println (i7 = =i8); to System.out.println (I7.equals (i8)); + - //by looking at the source code, we know that for data between 128 and 127, a data buffer pool is made, and if the data is within that range, no new space is created each time the //Integer II = integer.valueof (127); * } $}
The results of the program run:
Java Fundamentals Hardening 68: Face questions for the integer direct assignment of the basic type wrapper class