直入正題。
JDK1.6
JDK1.6
getBoolean
public static boolean getBoolean(String name)
- 當且僅當以參數命名的系統屬性存在,且等于
"true"
字符串時,才返回true
。(從 JavaTM 平臺的 1.0.2 版本開始,字符串的測試不再區分大小寫。)通過getProperty
方法可訪問系統屬性,此方法由System
類定義。如果沒有以指定名稱命名的屬性或者指定名稱為空或 null,則返回
false
。
源碼:1public static boolean getBoolean(String name) {
2boolean result = false;
3try {
4result = toBoolean(System.getProperty(name));
5} catch (IllegalArgumentException e) {
6} catch (NullPointerException e) {
7}
8return result;
9}
result = toBoolean(System.getProperty(name)); //當且僅當以參數命名的系統屬性存在,且等于"true"
字符串時,才返回true;
測試:1/**
2* 測試Boolean類getBoolean(String name)方法
3* @author dood
4* @version 1.0
5* 創建時間:2011-12-2
6*/
7public class BooleanTest {
8
9public static void main(String[] args) {
10Boolean bool = Boolean.valueOf(true);
11System.setProperty("isTrue", "true");
12System.out.println(bool.getBoolean("isTrue")); //true
13}
14}
15