Boolean 使用

<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:1; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:variable; mso-font-signature:0 0 0 0 0 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610611985 1073750139 0 0 159 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-font-kerning:1.0pt;} a:link, span.MsoHyperlink {mso-style-noshow:yes; mso-style-priority:99; color:blue; mso-themecolor:hyperlink; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {mso-style-noshow:yes; mso-style-priority:99; color:purple; mso-themecolor:followedhyperlink; text-decoration:underline; text-underline:single;} span.EmailStyle16 {mso-style-type:personal; mso-style-noshow:yes; mso-style-unhide:no; mso-ansi-font-size:10.5pt; mso-bidi-font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; color:windowtext;} span.barblack {mso-style-name:barblack; mso-style-unhide:no;} span.cardtype {mso-style-name:cardtype; mso-style-unhide:no;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->

 [ ]java.lang.Boolean 查看 (79) |2009-11-15 13:19:32

Boolean 类将基本类型为 boolean 的值包装在一个对象中。一个 Boolean 类型的对象只包含一个类型为 boolean 的字段。
    
此外,此类还为 boolean String 的相互转换提供了许多方法,并提供了处理 boolean 时非常有用的其他一些常量和方法。

 

方法

1

private static boolean toBoolean(String name)

<<  历史版本

该方法将字符串转为 boolean 类型数据,不区分大小写。
    private static boolean toBoolean(String name){
     return ((name != null) && name.equalsIgnoreCase("true"));
    }

作者 :100000

评论 :0

:0

 

不好 :0

 

错误 :0

 

2009-12-14 14:05:23

      

例子

1

Boolean使用示例 1

<<  历史版本

// 新建一个值为 true Boolean 对象,对象地址作为值赋给变量 b
    Boolean b = new Boolean(true);
    // 1
、打印结果为 false ,对象间作 == 操作时比较地址。
    System.out.println(Boolean.TRUE == b);
    // 2
、打印结果为 true ,比较对应基类型本值。
    System.out.println(Boolean.TRUE.equals(b));
    //
Boolean.TRUE 对象地址作为值赋给变量 b
    b = true;
    // 3
、打印结果为 true Boolean.TRUE b 指向同一个对象,地址相等。
    System.out.println(Boolean.TRUE == b);
    // 4
、打印结果为 true Boolean.TRUE 对象先转化为基本类型后的值和 true 比较。
    System.out.println(Boolean.TRUE == true);
    b = null;
    // 5
、打印结果为 java.lang.NullPointerException 异常信息, b 对象转化为基本类型时发生异常。
    // System.out.println(b == true);
    //
5 b 对象转化为基本类型时发生异常。
    // boolean pb = b;
    // 6
、打印结果为 false ,比较地址,因此不会抛出异常。
    System.out.println(b == Boolean.TRUE);
 

总结: 1 、将基本类型 true false 赋值给一个 Boolean 对象时会将 Boolean.TRUE Boolean.FALSE 赋值给该对象。
             
2 Boolean 对象和基本类型互操作时,会先将 Boolean 对象转化为基本类型。
             
3 、当出现 Boolean 对象转化为基本类型时,应确保该 Boolean 对象不为 null

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值