getBoolean(字符串str)和布尔类的valueOf(字符串str)给出了不同的输出 [英] getBoolean(String str) and valueOf(String str) of Boolean class gives different output

查看:127
本文介绍了getBoolean(字符串str)和布尔类的valueOf(字符串str)给出了不同的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很惊讶地知道, getBoolean()的valueOf()方法返回的diff输出相同的字符串输入。

我试图传递
字符串str =真
来这两种方法。但 getBoolean()给我错误的输出,而的valueOf()给我正确的输出是真实的。为什么?

家伙需要你的意见?

问候,
马亨德拉


解决方案

                                              的API的文档是你的朋友。


  • <一个href=\"http://docs.oracle.com/javase/7/docs/api/java/lang/Boolean.html#getBoolean%28java.lang.String%29\"><$c$c>Boolean.getBoolean可能不会做你认为它的作用:


      

    返回true,当且仅当 系统属性 命名的参数存在且等于字符串true。





  • <一个href=\"http://docs.oracle.com/javase/7/docs/api/java/lang/Boolean.html#valueOf%28boolean%29\"><$c$c>Boolean.valueOf然而,被描述为一个可以预期:


      

    布尔返回如果字符串参数不为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆