JAVA-基本数据类型

基本数据类型

一 JAVA中基本数据类型.

3种8类数据类型

数字型:byte、short、int、long、float、double

字符型:char

布尔型:boolean

基本数据类 位数 字节 默认值 包装类
byte 8 1 0 Byte
short 16 2 0 Short
int 32 4 0 Integer
long 64 8 0L Long
float 32 4 0f Float
double 64 8 0d Double
char 16 2 u0000 Character
boolen 1 flase

二 自动拆箱与装箱

装箱:将基本数据类型包装为其引用类型。

Integer i=10;

拆箱:将包装类类型转换为基本数据类型。

int n=i;

装箱与擦拆箱是如何实现的

装箱:在装箱的时候自动调用valueof()方法。

拆箱:在拆箱的时候自动调用xxxValue方法。

基本包装类与常量池

Byte、Short、Int、Long默认创建数值[-128,127]的相应数据类型的缓存数据。

Character默认创建[0,127]]的相应数据类型的缓存数据。

Boolean直接返回True、Flase

更细内容参考:https://www.cnblogs.com/dolphin0520/p/3780005.html


posted @ 2020-12-22 21:31  胡木杨  阅读(96)  评论(0)    收藏  举报