Convert double primitive type to a Double object in Java

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 11-Dec-2018 05:57:54
Advertisements