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中的布尔值与布尔值
基础教程推荐
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
