Home »
Java programming language
Java Double class parseDouble() method with example
Double class parseDouble() method: Here, we are going to learn about the parseDouble() method of Double class with its syntax and example.
Submitted by Preeti Jain, on September 23, 2019
Double class parseDouble() method
- parseDouble() method is available in java.lang package.
- parseDouble() method is used to return the double value corresponding to the given String or in other words we can say this method is used to convert a string value to double value.
- parseDouble() method is a static method, it is accessible with the class name too and if we try to access the method with the class object then also we will not get an error.
- parseDouble() method may throw a NumberFormatException at the time of conversion from string double,
NumberFormatException: In this exception, when the string argument does not have parsable double.
Syntax:
public static double parseDouble(String str);
Parameter(s):
- String str – represents the string value to be parsed.
Return value:
The return type of this method is double, it returns the corresponding double value.
Example:
// Java program to demonstrate the example
// of parseDouble(String str) method of Double class
public class ParseDoubleOfDoubleClass {
public static void main(String[] args) {
// Variables initialization
String str1 = "100";
String str2 = "6.7";
// Object initialization
Double d1 = new Double(str2);
// It convert string into double by calling parseDouble() method
// and store the result in another variable of double type
double result = d1.parseDouble(str1);
// Display result
System.out.println("d1.parseDouble(str1): " + result);
}
}
Output
d1.parseDouble(str1): 100.0
TOP Interview Coding Problems/Challenges