我想将 String
转换为 Double
数据类型。我不知道我应该使用 parseDouble
还是 valueOf
。
这两种方法有什么区别?
最佳答案
parseDouble
返回包含字符串值的原始 double :
Returns a new double initialized to the value represented by the specified String, as performed by the valueOf method of class Double.
valueOf
返回一个 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
关于java - Double.parseDouble(String) 和 Double.valueOf(String) 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10577610/