最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
详谈java中boolean和Boolean的区别
时间:2017-05-24 编辑:简简单单 来源:一聚教程网
boolean是基本数据类型 Boolean是它的封装类,和其他类一样,有属性有方法,可以new,
例如: Boolean flag = new Boolean("true"); // boolean 则不可以!
Boolean 是boolean 的实例化对象类,和Integer对应int一样自jdk1.5.0以上版本后,Boolean在"赋值"和判断上和boolean一样,
即是你:
boolean b1 = true ;
或者
Boolean b2 = true ;
都可以。
唯一只能使用Boolean上的就是从列表或者哈希表获取值时。
比如
boolean t = false;
Map map = new HashMap();
map.put("t", t);
那么获取值时只能用
Boolean t1 = (Boolean) map.get(t); //前面只能用Boolean强制转换,不能使用boolean.
通过上面的分析,我们可以得出:
在java中大部分情况我们使用int,boolean基础类型就可以了,只有要封装集合的时候,使用Integer和Boolean。
相关文章
- SpringBoot测试配置属性与web启动环境解析 10-24
- vue中将el-switch值true、false改为number类型的1和0解析 10-24
- Vue中的路由配置项meta使用解读 10-24
- SpringBoot自定义bean绑定解析 10-24
- SpringBoot常用计量与bean属性校验和进制数据转换规则解析 10-24
- 工厂方法在Spring框架中的运用介绍 10-24