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.getBoolean
probably doesn't do what you think it does:
当且仅当 system由参数命名的属性存在且等于字符串true".
Boolean.valueOf
可能就是你要找的:
Boolean.valueOf
is probably what you're looking for:
如果字符串参数不为空并且等于字符串true",则返回的布尔值表示值 true.
这篇关于Boolean 类的 getBoolean(String str) 和 valueOf(String str) 给出不同的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Boolean 类的 getBoolean(String str) 和 valueOf(String str) 给出不同的输出


- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01