java foundation - wrapper class

1. Type conversion

(1) Basic type --> String: 2 + ""

(2) Packaging type --> String : i.toString();

(3) String----->Package type: Integer.parseInt()

2. The wrapper type overrides hashCode, equals, cmopareTo

3. Automatic packing and automatic unpacking

4. Integer i1 = 250; Integer i2 = 250 i1==i2 The result is false

  Integer i1 = 120; Integer i2 = 120 i1==i2 is true

 Integer is a wrapper type. Logically speaking, when using ==, the result should be false, and the comparison is the address. But if the data is in the byte range -128-127, the memory will not be re-opened. will be cached. Improve efficiency



 



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324873708&siteId=291194637