| 數據類型 | 包裝類 | 字節長度 | 默認值 | 有效位 |
| byte | Byte | 1 | 0 | -128~127 |
| short | Short | 2 | 0 | -32768~32767 |
| int | Integer | 4 | 0 | -2^31-1~2^31 |
| long | Long | 8 | 0l或0L | -2^63~2^63-1 |
| float | Float | 4 | 0.0f或0.0F | 24(二進制)=7~8(十進制) |
| double | Double | 8 | 0.0 | 53(二進制)=10~11(十進制) |
| char | Character | 2 | u0000 | |
| boolean | Boolean | 1 | false |
包裝類是引用類型,用==和equels比較時應當注意一下!
1 Short packShort=1; 2 short baseShort=1; 3 Integer packInt=1; 4 int baseInt=1; 5 //用Short的equals()方法與short進行比較 6 System.out.println(packShort.equals(baseShort)); 7 //用==比較Short和short 8 System.out.println(packShort==baseShort); 9 //用Short的equals()方法與int進行比較 10 System.out.println(packShort.equals(baseInt)); 11 //用Short的equals()方法與Integer進行比較 12 System.out.println(packShort.equals(packInt)); 13 //用==比較Short和int 14 System.out.println(packShort==baseInt);
結果:
1 true 2 true 3 false 4 false 5 true
