Boolean vs boolean in Java(Java中的布尔值与布尔值)
问题描述
有关于 Java 中的 Integer 与 int 的讨论.前者的默认值为null,而后者的默认值为0.Boolean vs boolean 怎么样?
There are discussions around Integer vs int in Java. The default value of the former is null while in the latter it's 0. How about Boolean vs boolean?
我的应用程序中的变量可以有 0/1 值.我想使用 boolean/Boolean 而不想使用 int.我可以改用 Boolean/boolean 吗?
A variable in my application can have 0/1 values. I would like to use boolean/Boolean and prefer not to use int. Can I use Boolean/boolean instead?
推荐答案
是你可以使用 Boolean/boolean 代替.
Yes you can use Boolean/boolean instead.
第一个是对象,第二个是原始类型.
First one is Object and second one is primitive type.
第一个,你会得到更多有用的方法.
On first one, you will get more methods which will be useful.
考虑到内存开销,第二个很便宜 第二个会节省更多内存,所以去吧
现在选择你的方式.
这篇关于Java中的布尔值与布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Java中的布尔值与布尔值
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
