java语言:为什么输出b的值为:false?

boolean y=true;
String s1=String.valueof(y);
boolean b=Boolean.getBoolean(s1);
System.out.println("b="+b);
为什么输出b的值为:false?

getBoolean(String name)
当且仅当以参数命名的系统属性存在,且等于 "true" 字符串时,才返回 true。通过 getProperty 方法可访问系统属性,此方法由 System 类定义。
如果没有以指定名称命名的属性或者指定名称为空或 null,则返回 false。

参见:System.getProperty(java.lang.String)
要返回true这样
boolean b=Boolean.valueOf(s1);追问

那么如何设置系统属性呢?

追答

windows XP系统在:我的电脑 右键属性 高级 环境变量中设置

追问

我就是那样设置以后,仍然得不出true,才进行追问的。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-03-24
Returns true if and only if the system property named by the argument exists and is equal to the string "true". (Beginning with version 1.0.2 of the JavaTM platform, the test of this string is case insensitive.) A system property is accessible through getProperty, a method defined by the System class.
If there is no property with the specified name, or if the specified name is empty or null, then false is returned.

Parameters:
name - the system property name.
Returns:
the boolean value of the system property.

这是获得系统变量用的,参考这样
Properties p = System.getProperties();
p.setProperty( "test ", "true ");
System.out.println( "Boolean.getBoolean(): " + Boolean.getBoolean( "test "));
第2个回答  2011-03-28
因为s1是字符串,所以Boolean.getBoolean(s1)的返回值为false.API中关于Boolean的getBoolean()方法的定义为当且仅当以参数命名的系统属性存在,且等于 "true" 字符串时,才返回 true。虽然s1为true字符串,但没有以参数命名的系统属性存在,所以返回值为false.追问

那么如何设置系统属性呢?

第3个回答  2011-03-24
因为系统属性中没有等于"true"的属性。
相似回答