Double.parseDouble(String)和Double.valueOf(String)有什么区别? [英] What is the difference between Double.parseDouble(String) and 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
returns a primitive double containing the value of the string:
返回一个新的double,该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
返回一个双重实例(如果已经缓存),您将获得相同的缓存实例.
valueOf
returns a Double instance, if already cached, you'll get the same cached instance.
返回一个Double实例,该实例表示指定的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.
To avoid the overhead of creating a new Double object instance, you should normally use valueOf
这篇关于Double.parseDouble(String)和Double.valueOf(String)有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!