What is the difference between Double.parseDouble(String) and Double.valueOf(String)?(Double.parseDouble(String) 和 Double.valueOf(String) 有什么区别?)
问题描述
我想将 String
转换为 Double
数据类型.我不知道我应该使用 parseDouble
还是 valueOf
.
I want to convert String
to a Double
data type. I do not know if I should use parseDouble
or valueOf
.
这两种方法有什么区别?
What is the difference between these two methods?
推荐答案
parseDouble
返回一个包含字符串值的原始双精度:
parseDouble
returns a primitive double containing the value of the string:
返回一个新的 double,初始化为指定 String 表示的值,由 Double 类的 valueOf 方法执行.
Returns a new double initialized to the value represented by the specified String, as performed by the valueOf method of class Double.
valueOf
返回一个 Double 实例,如果已经缓存,你会得到相同的缓存实例.
valueOf
returns a Double instance, if already cached, you'll get the same cached instance.
返回一个表示指定双精度值的 Double 实例.如果不需要一个新的 Double 实例,这个方法一般应该是优先于构造函数 Double(double) 使用,因为此方法可能会产生显着更好的空间和时间性能缓存频繁请求的值.
Returns a Double instance representing the specified double value. If a new Double instance is not required, this method should generally be used in preference to the constructor Double(double), as this method is likely to yield significantly better space and time performance by caching frequently requested values.
为避免创建新的 Double 对象实例的开销,您通常应该使用 valueOf
To avoid the overhead of creating a new Double object instance, you should normally use valueOf
这篇关于Double.parseDouble(String) 和 Double.valueOf(String) 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Double.parseDouble(String) 和 Double.valueOf(String) 有什么


基础教程推荐
- 如何强制对超级方法进行多态调用? 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01