当前位置: 代码迷 >> J2SE >> java中的 boolean 在内存中占多少字节?该怎么解决
  详细解决方案

java中的 boolean 在内存中占多少字节?该怎么解决

热度:417   发布时间:2016-04-24 00:50:41.0
java中的 boolean 在内存中占多少字节?
java中的 boolean 在内存中占多少字节?

------解决方案--------------------
1个字节吧
------解决方案--------------------
就一个。。
------解决方案--------------------
主类型 大小 最小值 最大值 封装器类型
boolean 1 位 - - Boolean
char 16 位 Unicode 0 Unicode 2 的16 次方-1 Character
byte 8 位 -128 +127 Byte(注释①)
short 16 位 -2 的15 次方 +2 的15 次方-1 Short(注释①)
int 32 位 -2 的31 次方 +2 的31 次方-1 Integer
long 64 位 -2 的63 次方 +2 的63 次方-1 Long
float 32 位 IEEE754 IEEE754 Float
double 64 位 IEEE754 IEEE754 Double

^_^把别人的答案复制来
------解决方案--------------------
boolean占1个bit,1/8个字节。
------解决方案--------------------
对 boolean 只要0 1表示false true 一个位就行啦
------解决方案--------------------
4楼正确
------解决方案--------------------
boolean占1个bit,1/8个字节。
------解决方案--------------------
1个bit
------解决方案--------------------
sun's Data Types introduction:
byte: The byte data type is an 8-bit signed two's complement integer
short: The short data type is a 16-bit signed two's complement integer
int: The int data type is a 32-bit signed two's complement integer
long: The long data type is a 64-bit signed two's complement integer
float: The float data type is a single-precision 32-bit IEEE 754 floating point
double: The double data type is a double-precision 64-bit IEEE 754 floating point.
char: The char data type is a single 16-bit Unicode character
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.

我看你们所说的,我吓了一跳,我记得boolean就2个字面值true/false,难道java的基本类型变了?
我刚刚看了一下文当,文档说得很清楚嘛. This data type represents one bit of information, but its "size" isn't something that's precisely defined.
这个数据类型表现为1bit的信息,但是他的大小不是明确指定的.
is和represents完全是2回事嘛!,可以认为他是一个1bit的,但是他的大小不是明确指定的

to 5楼的
对 boolean 只要0 1表示false true 一个位就行啦
哥们你说的是C++吧,反正我在Java中没见过,用1表示true 0表示false的
------解决方案--------------------
就只有一位
------解决方案--------------------

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.
------解决方案--------------------
理解了许多,谢谢上面的讨论
------解决方案--------------------
一位就可以了,即0和1
------解决方案--------------------
根据我---一个刚学java的人---所知
 boolean占1byte.
------解决方案--------------------
不知道,我不发表意见。
------解决方案--------------------
我对上面的说法置疑
(1)在虚拟机里boolean在编译成字节码时会用int或byte来表示。false用整数0表示,true用非零整数表示。涉及boolean的操作是用int进行的。boolean数据是当成byte数组进行访问的。
(2)JAVA虚拟机中,基本的数据单元是字(word)大小由虚拟机的设计而定。一般为32位。虚拟机的局部变量和操作数栈都是按照字来字义的。
  相关解决方案