Boolean和boolean的区别

[size=medium]boolean是基本数据类型;
Boolean是它的封装类,和其他类一样,有属性有方法,可以new,也可以直接赋值,例如:
Boolean a = new Boolean(true);
也可以 Boolean a = true;
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 = [color=red](Boolean)[/color] map.get(t); //前面只能用Boolean强制转换,不能使用boolean.

示例二:

int t = 0;
Map map = new HashMap();
map.put("t", t);
int t1 = [color=red](Integer) [/color]map.get(t);
总言:[color=blue]放进map中的可以是元素或者对象,拿出来的一定是一个对象,强制转换时必须使用大些Boolean或Integer[/size][/color]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值