|NO.Z.00008|——————————|BigDataEnd|——|Java&核心类库.V08|——|Java.v08|Boolean类|概念使用|

一、Boolean类的概念和使用
### --- 基本概念

~~~     ——>        java.lang.Boolean类型内部包装了一个boolean类型的变量作为成员变量,
~~~     ——>        主要用于实现对boolean类型的包装并提供boolean类型到String类之间的转换等方法。
二、常用的常量
常量类型和名称 功能介绍
public static final Boolean FALSE  对应基值为false的对象
public static final Boolean TRUE 对应基值为true的对象
public static final Class TYPE 表示boolean类型的Class实例
三、常用的方法
方法声明 功能介绍
Boolean(boolean value) 根据参数指定的布尔数值来构造对象(已过时)
Boolean(String s)  根据参数指定的字符串来构造对象 (已过时)
boolean booleanValue() 获取调用对象中的布尔数值并返回
static Boolean valueOf(boolean b) 根据参数指定布尔数值得到Boolean类型对象
boolean equals(Object obj) 比较调用对象与参数指定的对象是否相等
String toString() 返回描述调用对象数值的字符串形式
static boolean parseBoolean(String s) 将字符串类型转换为boolean类型并返回
四、编程代码
package com.yanqi.task11;

public class BooleanTest {

    public static void main(String[] args) {

        // 1.在Java5之前采用方法进行装箱和拆箱
        // 相当于从boolean类型到Boolean类型的转换,装箱
        Boolean bo1 = Boolean.valueOf(true);
        System.out.println("bo1 = " + bo1); // true
        boolean b1 = bo1.booleanValue();
        System.out.println("b1 = " + b1); // true

        System.out.println("----------------------------------------------");
        // 2.从Java5开始支持自动装箱和拆箱
        Boolean bo2 = false;
        boolean b2 = bo2;
        System.out.println("b2 = " + b2); // false

        System.out.println("----------------------------------------------");
        // 3.实现从String类型到boolean类型的转换
        //boolean b3 = Boolean.parseBoolean("112");
        // 该方法的执行原理是:只要参数数值不为true或者TRUE时,则结果就是false,查手册和源码
        boolean b3 = Boolean.parseBoolean("TRUE");
        System.out.println("b3 = " + b3); // true
    }
}
五、编译打印
D:\JAVA\jdk-11.0.2\bin\java.exe "-javaagent:D:\IntelliJIDEA\IntelliJ IDEA 2019.3.3\lib\idea_rt.jar=49897:D:\IntelliJIDEA\IntelliJ IDEA 2019.3.3\bin" -Dfile.encoding=UTF-8 -classpath E:\NO.Z.10000——javaproject\NO.H.00001.javase\javase\out\production\javase com.yanqi.task11.BooleanTest
bo1 = true
b1 = true
----------------------------------------------
b2 = false
----------------------------------------------
b3 = true

Process finished with exit code 0

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

posted on   yanqi_vip  阅读(26)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示