What is the size of a boolean variable in Java?

2019-01-02 17:18发布

Can any one tell the bit size of boolean in Java?

标签: java boolean
8条回答
查无此人
2楼-- · 2019-01-02 18:18

The actual information represented by a boolean value in Java is one bit: 1 for true, 0 for false. However, the actual size of a boolean variable in memory is not precisely defined by the Java specification. See Primitive Data Types in Java.

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.

查看更多
牵手、夕阳
3楼-- · 2019-01-02 18:18

On a side note...

If you are thinking about using an array of Boolean objects, don't. Use a BitSet instead - it has some performance optimisations (and some nice extra methods, allowing you to get the next set/unset bit).

查看更多
登录 后发表回答