Java Double - valueOf() Method
The java.lang.Double.valueOf() method returns a Double instance representing the specified double value. If a new Double instance is not required, this method should generally be used in preference to the constructor Double(double), as this method is likely to yield significantly better space and time performance by caching frequently requested values.
Syntax
public static Double valueOf(double d)
Parameters
d |
Specify a double value. |
Return Value
Returns a Double instance representing d.
Exception
NA.
Example:
In the example below, the java.lang.Double.valueOf() method returns a Double instance representing the given double value.
import java.lang.*; public class MyClass { public static void main(String[] args) { //creating double value double x = 25.5; //creating Double instance Double y = Double.valueOf(x); //printing the double value System.out.println("The double value is: " + x); //printing the Double instance System.out.println("The Double instance is: " + y); } }
The output of the above code will be:
The double value is: 25.5 The Double instance is: 25.5
❮ Java.lang - Double