getBoolean(String str) and valueOf(String str) of Boolean class gives different output(Boolean 类的 getBoolean(String str) 和 valueOf(String str) 给出不同的输出)
问题描述
我很惊讶地知道 getBoolean() 和 valueOf() 方法对相同的输入字符串返回不同的结果.
I am surprised to know that getBoolean() and valueOf() method returns different results for the same input string.
我已尝试将 "true" 传递给这两种方法.但是 getBoolean() 给了我错误的输出,而 valueOf() 给了我正确的输出是正确的.为什么?
I have tried to pass the "true" to both the methods. But getBoolean() gives me false output whereas valueOf() gives me right output that is true. Why?
推荐答案
API 文档是您的朋友.
The API-documentation is your friend.
Boolean.getBoolean可能不会像您认为的那样:
Boolean.getBooleanprobably doesn't do what you think it does:
当且仅当 system由参数命名的属性存在且等于字符串true".
Boolean.valueOf可能就是你要找的:
Boolean.valueOfis probably what you're looking for:
如果字符串参数不为空并且等于字符串true",则返回的布尔值表示值 true.
这篇关于Boolean 类的 getBoolean(String str) 和 valueOf(String str) 给出不同的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Boolean 类的 getBoolean(String str) 和 valueOf(String str) 给出不同的输出
基础教程推荐
- 存储 20 位数字的数据类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- Struts2 URL 无法访问 2022-01-01
