这是一个非常简单而且可能毫无值(value)的问题:以下两者中哪一个消耗更多内存?
boolean[][] var = new boolean[32768][32768];
或
byte[][] var = new byte[32768][32768];
我听到谣言 java
将每条数据存储在它自己的byte
中在这两种情况下。那么哪一种更有效呢?是否有可能以某种方式治疗 long
值为 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.
但是,在 Oracle JVM 中,它每位使用 1 个字节,因此内存大小和效率是相同的。
如果您想使用每位 1 位,我建议使用 BitSet。
Is it possible to somehow treat a long value as a boolean array?
是的,虽然我无法想象你为什么想要这样做。
关于java - boolean 值与 boolean 值字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36105018/