Convert double primitive type to a Double object in Java


To convert double primitive type to a Double object, you need to use Double constructor.

Let’s say the following is our double primitive.

// double primitive
double val = 23.78;

To convert it to a Double object, use Double constructor.

// Double object
Double ob = new Double(val);

Example

 Live Demo

public class Demo {
   public static void main(String args[]) {
      // double primitive
      double val = 23.78;
      // Double object
      Double ob = new Double(val);
      System.out.println(ob);
   }
}

Output

23.78

Updated on: 26-Jun-2020

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements