getBoolean(字符串str)和布尔类的valueOf(字符串str)给出了不同的输出 [英] getBoolean(String str) and valueOf(String str) of Boolean class gives different output
问题描述
我很惊讶地知道, getBoolean()
和的valueOf()
方法返回的diff输出相同的字符串输入。
我试图传递字符串str =真
来这两种方法。但 getBoolean()
给我错误的输出,而的valueOf()
给我正确的输出是真实的。为什么?
家伙需要你的意见?
问候,
马亨德拉
-
<一个href=\"http://docs.oracle.com/javase/7/docs/api/java/lang/Boolean.html#getBoolean%28java.lang.String%29\"><$c$c>Boolean.getBoolean$c$c>可能不会做你认为它的作用:
的返回true,当且仅当 系统属性 命名的参数存在且等于字符串true。的
块引用>
-
<一个href=\"http://docs.oracle.com/javase/7/docs/api/java/lang/Boolean.html#valueOf%28boolean%29\"><$c$c>Boolean.valueOf$c$c>然而,被描述为一个可以预期:
的布尔返回如果字符串参数不为null,等于,忽略大小写字符串真正的重presents值true。的
块引用>
I am surprised to know that getBoolean()
and valueOF()
method returns diff output for the same string input.
I have tried to pass the
String str = "true"
to both the methods. But getBoolean()
gives me false output whereas valueOF()
gives me right output that is true. why??
Guys need your comments?
Regards, Mahendra
The API-documentation is your friend.
Boolean.getBoolean
probably doesn't do what you think it does:Returns true if and only if the system property named by the argument exists and is equal to the string "true".
Boolean.valueOf
however, is described as one may expect:The Boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string "true".
这篇关于getBoolean(字符串str)和布尔类的valueOf(字符串str)给出了不同的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!