Double wrapper class is used to wrap primitive data type double value in an object.
Examples of Double Wrapper Class
Example 1 : Convert double to Double object
public class doubleToDouble
{
public static void main(String[] args)
{
double d = 1.2;
Double dObj = new Double(d);
System.out.println(dObj);
}
}
Output
1.2
This example shows how a double data type value can be converted to a Double object.
Example 2 : Convert Double object to String object
public class DoubleToString
{
public static void main(String[] args)
{
Double dObj = new Double(1.2);
String str = dObj.toString();
System.out.println("Double converted to String as " + str);
}
}
Output
Double converted to String as 1.2
This example shows how a Double object can be converted into a String object.