java.lang.Boolean.getBoolean(String name) 當且僅當存在以引數命名的系統屬性和等於該字串“true”,則返回true。系統屬性通過getProperty方法,通過System類中定義的方法存取。
如果沒有指定名稱的屬性,或者如果指定名稱為空或null,則返回false。
以下是java.lang.Boolean.getBoolean()方法的宣告
public static boolean getBoolean(String name)
name - 系統屬性名稱
此方法返回系統屬性的布林值。
NA
下面的例子顯示lang.Boolean.getBoolean()方法的使用。
package com.yiibai; 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