假设我们在这里有Double对象。
Double obj = new Double("39.45");现在,如果要将此Double转换为短基本数据类型。为此,请使用内置shortValue()方法。
// converting to short primitive types short shortObj = obj.shortValue(); System.out.println(shortObj);
以相同的方式将Double转换为另一个数字原始数据类型int。为此,请使用内置intValue()方法。
// converting to int primitive types int intObj = obj.intValue(); System.out.println(intObj);
以下是将Double转换为数字基本类型short,int,float等的示例。
public class Demo {
   public static void main(String args[]) {
      Double obj = new Double("39.45");
      int intVal = obj.intValue();
      System.out.println(intVal);
      byte byteVal = obj.byteValue();
      System.out.println(byteVal);
      short shortVal = obj.shortValue();
      System.out.println(shortVal);
      float floatVal = obj.floatValue();
      System.out.println(floatVal);
      double doubleVal = obj.doubleValue();
      System.out.println(doubleVal);
   }
}输出结果
39 39 39 39.45 39.45