java boolean 方法_Java Boolean getBoolean()方法

Java Boolean getBoolean()方法

java.lang.Boolean.getBoolean(String name) 当且仅当存在以参数命名的系统属性和等于该字符串“true”,则返回true。系统属性通过getProperty方法,通过System类中定义的方法访问。

如果没有指定名称的属性,或者如果指定名称为空或null,则返回false。

1 语法

public static boolean getBoolean(String name)

2 参数

name:系统属性名称

3 返回值

此方法返回系统属性的布尔值。

4 示例

package com.yiidian;

/**

* 一点教程网: http://www.yiidian.com

*/

/**

* Java Boolean getBoolean()方法

*/

import java.lang.*;

public class BooleanDemo {

public static void main(String[] args) {

// create 2 boolean primitives bool1, bool2

boolean bool1, bool2;

/**

* using System class's setProprty method, set the values of

* system properties demo1, demo2.

*/

System.setProperty("demo1","true");

System.setProperty("demo2","abcd");

// retrieve value of system properties to s1, s2

String s1 = System.getProperty("demo1");

String s2 = System.getProperty("demo2");

// assign result of getBoolean on demo1, demo2 to bool1, bool2

bool1 = Boolean.getBoolean("demo1");

bool2 = Boolean.getBoolean("demo2");

String str1 = "boolean value of system property demo1 is " + bool1;

String str2 = "System property value of demo1 is " + s1;

String str3 = "boolean value of system property demo2 is " + bool2;

String str4 = "System property value of demo2 is " + s2;

// print bool1, bool2 and s1, s2 values

System.out.println( str1 );

System.out.println( str2 );

System.out.println( str3 );

System.out.println( str4 );

}

}

输出结果为:

boolean value of system property demo1 is true

System property value of demo1 is true

boolean value of system property demo2 is false

System property value of demo2 is abcd

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值