String param = "true";
System.out.println(Boolean.getBoolean(param));
Properties p = System.getProperties();
p.setProperty("true", "true");
System.out.println(Boolean.getBoolean(param));
System.out.println(Boolean.getBoolean(param.toUpperCase()));打印出  false ture false 为什么?
不是 当且仅当以参数命名的系统属性存在,且等于 "true" 字符串时,才返回 true。(从 JavaTM 平台的 1.0.2 版本开始,字符串的测试不再区分大小写。)通过 getProperty 方法可访问系统属性,此方法由 System 类定义。Boolean.java 如下
private static boolean toBoolean(String name) { 
return ((name != null) && name.equalsIgnoreCase("true"));
}

解决方案 »

  1.   

    不过我把你的代码放在一个类里面了:
    public class NewJFrame extends JFrame {
    public void isBoolean()
    {
    String param = "true"; 
    System.out.println(getBoolean(param)); 
    Properties p = System.getProperties(); 
    p.setProperty("true", "true"); 
    System.out.println(getBoolean(param)); 
    System.out.println(getBoolean(param.toUpperCase())); 
    }

       private boolean getBoolean(String name){ 
    return ((name != null) && name.equalsIgnoreCase("true")); 

       
        public static void main(String[] args)
        {
         NewJFrame jf = new NewJFrame();
         jf.isBoolean();
        }
    }
      

  2.   

    我也都是true啊,楼主你是怎么玩出来的,share一下了。
      

  3.   

    晕,我用的是eclipse3.2 和 3.5的
    这里的
    Boolean.java 如下 
    private static boolean toBoolean(String name) { 
    return ((name != null) && name.equalsIgnoreCase("true")); 

    是java源代码里面的,不是手写的。只运行这看看public static void main(String[] args){
    String param = "true"; 
    System.out.println(Boolean.getBoolean(param)); 
    Properties p = System.getProperties(); 
    p.setProperty("true", "true"); 
    System.out.println(Boolean.getBoolean(param)); 
    System.out.println(Boolean.getBoolean(param.toUpperCase())); 
    }
      

  4.   

    有什么问题?
    这个问题好像上次java大会上,举出的第一题。
    第一个是false,以为系统属性中没有等于"true"的属性。
    第二个为true,因为你是设置了。
    第三个为false,因为你转化了大写,和系统属性中的"true"不相同的。
      

  5.   


     public static boolean getBoolean(String name) {
            boolean result = false;
            try {
                result = toBoolean(System.getProperty(name));
            } catch (IllegalArgumentException e) {
            } catch (NullPointerException e) {
            }
            return result;
        }System.getProperty("TRUE");大写的时候,没有找到系统属性,则会返回null,如果为null或者没有指定的情况就会返回false。
      

  6.   

    再加上楼主的源码大家就明白了。private static boolean toBoolean(String name) { 
    return ((name != null) && name.equalsIgnoreCase("true")); 
      

  7.   

    Returns true if and only if the system property named by the argument exists and is equal to the string "true". 当系统中有以参数为key的property存在并且value为”true“字符串时候,返回true,否则返回false。
    第一个false是System中没有以true为key的属性。
    第二个true是设置过了
    第三个 false是去查找以TRUE为key的属性去了,结果没找到
      

  8.   

    第一个是false,以为系统属性中没有等于"true"的属性。 
    第二个为true,因为你是设置了。 
    第三个为false,因为你转化了大写,和系统属性中的"true"不相同的。正解 学习了 
      

  9.   

    API 中 Boolean.getBoolean(String name) 方法说
       当且仅当以参数命名的系统属性存在,且等于 "true" 字符串时,才返回 true。(从 JavaTM 平台的 1.0.2 版本开始,字符串的测试不再区分大小写。)通过 getProperty 方法可访问系统属性,此方法由 System 类定义。 
    private static boolean toBoolean(String name) { 
    return ((name != null) && name.equalsIgnoreCase("true"));name不是不区分大小写"true"么?