Java Double - valueOf() Method
The java.lang.Double.valueOf() method returns a Double object holding the double value represented by the argument string s. If s is null, then a NullPointerException is thrown.
Leading and trailing whitespace characters in s are ignored. Whitespace is removed as if by the String.trim() method; that is, both ASCII space and control characters are removed. The rest of s should constitute a FloatValue as described by the lexical syntax rules.
Syntax
public static Double valueOf(String s) throws NumberFormatException
Parameters
s |
Specify the string to be parsed. |
Return Value
Returns a Double object holding the value represented by the String argument.
Exception
Throws NumberFormatException, if the string does not contain a parsable number.
Example:
In the example below, the java.lang.Double.valueOf() method returns a Double object holding the value given by the specified String.
import java.lang.*; public class MyClass { public static void main(String[] args) { //creating a string holding double value String x = "25.2"; //creating Double object Double y = Double.valueOf(x); //printing the string System.out.println("The string is: " + x); //printing the Double object System.out.println("The Double object is: " + y); } }
The output of the above code will be:
The string is: 25.2 The Double object is: 25.2
❮ Java.lang - Double