加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

是否可以在Java中声明一个1位变量?

发布时间:2020-12-14 23:21:04 所属栏目:Java 来源:网络整理
导读:我的算法使用了一个庞大的布尔数组,正如我所教导的,每个布尔变量需要1个字节.无论如何都要声明一个布尔数组并减少内存使用量,因为我正在处理手机环境. 编辑:我的朋友和我正在讨论BitSet是否比普通布尔数组慢.请澄清一下.该算法仍然需要性能作为最佳需求. 解
我的算法使用了一个庞大的布尔数组,正如我所教导的,每个布尔变量需要1个字节.无论如何都要声明一个布尔数组并减少内存使用量,因为我正在处理手机环境.

编辑:我的朋友和我正在讨论BitSet是否比普通布尔数组慢.请澄清一下.该算法仍然需要性能作为最佳需求.

解决方法

BitSet

This class implements a vector of bits that grows as needed. Each
component of the bit set has a boolean value. The bits of a BitSet are
indexed by nonnegative integers. Individual indexed bits can be
examined,set,or cleared. One BitSet may be used to modify the
contents of another BitSet through logical AND,logical inclusive OR,
and logical exclusive OR operations.

Link to benchmark使用布尔与BitSet之间

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读