编程语言
首页 > 编程语言> > Java Double类valueOf()方法及示例

Java Double类valueOf()方法及示例

作者:互联网

转自:

http://www.java265.com/JavaCourse/202205/3576.html

下文笔者讲述Double.valueOf()方法的功能简介说明,如下所示:

    public static Double valueOf (double value);
    public static Double valueOf (String value);

valueOf可能出现异常的情况:
  NullPointerException:
     当传入的值是null时,则会报此异常错误
  NumberFormatException:
     传入的数值异常 
public class ValueOfDoubleClass {
    public static void main(String[] args) { 
        Double ob1 = new Double("80.30");
        Double ob2 = new Double("80.30");
  
        System.out.println("ob1: " + ob1);
        System.out.println("ob2: " + ob2);
  
        Double value1 = ob1.valueOf(90.11d);
  
        String s = "90"; 
        Double value2 = ob2.valueOf(s);
  
        System.out.println("ob1.valueOf(80.11d): " + value1);
        System.out.println("ob2.valueOf(s): " + value2);
    }
} 

 

标签:示例,Double,valueOf,System,out,ob2,ob1
来源: https://www.cnblogs.com/java265/p/16329473.html