直入正題。

JDK1.6

getBoolean

public static boolean getBoolean(String name)
當且僅當以參數命名的系統屬性存在,且等于 "true" 字符串時,才返回 true。(從 JavaTM 平臺的 1.0.2 版本開始,字符串的測試不再區分大小寫。)通過 getProperty 方法可訪問系統屬性,此方法由 System 類定義。

如果沒有以指定名稱命名的屬性或者指定名稱為空或 null,則返回 false

源碼:

1    public static boolean getBoolean(String name) {
2        boolean result = false;
3        try {
4            result = toBoolean(System.getProperty(name));
5        }
 catch (IllegalArgumentException e) {
6        }
 catch (NullPointerException e) {
7        }

8        return 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    
 9    public static void main(String[] args) {
10        Boolean bool = Boolean.valueOf(true);
11        System.setProperty("isTrue""true");
12        System.out.println(bool.getBoolean("isTrue")); //true
13    }

14}

15