問題描述
我想將 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) 有什么區別?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!