Double.valueOf(String s)和Double.ParseDouble(String s)之间的区别是什么? [英] Whats the difference between Double.valueOf(String s) and Double.ParseDouble(String s)?

查看:644
本文介绍了Double.valueOf(String s)和Double.ParseDouble(String s)之间的区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解文档,ParseDouble函数类似于:

As I understand the doc, ParseDouble function made something like :

 Double parseDouble(String s) throws ... {       
      return new Double(Double.valueOf(s));
 }


推荐答案

逻辑相同,但是Double.valueOf()的返回值返回一个堆分配的Double对象,其中parseDouble返回一个原始double。您的代码示例不太正确。 java源代码读取:

The logic is the same, but the return value of Double.valueOf() return a heap allocated Double object, where as parseDouble returns a primitive double. Your code example is not quite correct. The java source reads:

public static double parseDouble(String s) throws NumberFormatException {
    return FloatingDecimal.readJavaFormatString(s).doubleValue();
}

public static Double valueOf(String s) throws NumberFormatException {
    return new Double(FloatingDecimal.readJavaFormatString(s).doubleValue());
}

这篇关于Double.valueOf(String s)和Double.ParseDouble(String s)之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆