java基本烈性占用字节数,Java八种基本数据类型占用字节数空间介绍

大家都知道在

byte:1字节

short:2字节

int:4字节

long:8字节

char:2字节

float:4字节

double:8字节

boolean:不确定

本来boolean应该只占用1bit也就是1/8字节的,但实际上,由于Java的实际寻址单元最小是byte即1字节,所以所以实际上boolean占用的是可能是1bit,也可能是更多,这个是不确定的。下面是Sun的官方介绍。

boolean: The boolean data type has only two possible values: true and false.

Use this data type for simple flags that track true/false conditions. This data type represents one bit of information,

but its "size" isn't something that's precisely defined.

再下面是

Where Java programming language boolean values are mapped by compilers to values of Java virtual machine type int, the compilers must use the same encoding.

所以只是单纯的boolean b = true;这里的b占用4个字节,和int一样。

而紧接着下面还有一段:

Arrays of type boolean are accessed and modified using the byte array instructions

In Sun's JDK releases 1.0 and 1.1, and the Java 2 SDK, Standard Edition, v1.2, boolean arrays in the Java programming language are encoded as Java virtual machine byte arrays, using 8 bits per boolean element.

所以说boolean[] b = new boolean[10];这样的数组中每个值占用的空间是1字节。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值