Java.lang Package Classes

Java Double - toString() Method



The java.lang.Double.toString() method returns a string representation of this Double object. The primitive double value represented by this object is converted to a string exactly as if by the method toString of one argument.

Syntax

public String toString()

Parameters

No parameter is required.

Return Value

Returns a String representation of this object.

Exception

NA.

Example:

In the example below, the java.lang.Double.toString() method returns a String object representing the given Double's value.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating Double object
    Double x = 25.2;

    //printing the Double object 
    System.out.println("The Double object is: " + x); 

    //creating and printing the string representation
    //of the Double object's value
    String x_tostring = x.toString();
    System.out.println("The string value of Double is: " + x_tostring);   
  }
}

The output of the above code will be:

The Double object is: 25.2
The string value of Double is: 25.2

❮ Java.lang - Double