Java Wrapper Class: Double

Get a brief introduction to Double, a Java wrapper class.

Introducing Double

The Double class is part of the java.lang package.

The Double class is a wrapper class for the primitive type double. It contains several methods to deal with double type values effectively. An object of Double class can hold a single double value.

Creating a Double object

This class has two constructors:

  • Double (double value)
  • Double (String string)

Let’s cover them one by one.

The Double (double value) constructor

This constructor constructs a new Double object that represents the specified double value.

Look at the program below.

Press + to interact
class DoubleWrapperDemo1
{
public static void main(String args[])
{
Double x = new Double(5); // Creating an Double type object
System.out.println(x);
}
}

Look at line 5. We create the Double object, called x. We pass 55 as the argument. Now, when we try to print x, we get 5.05.0 ...