Double parseDouble() method in Java with examples Last Updated : 26 Oct, 2018 Comments Improve Suggest changes Like Article Like Report The parseDouble() method of Java Double class is a built in method in Java that returns a new double initialized to the value represented by the specified String, as done by the valueOf method of class Double. Syntax: public static double parseDouble(String s) Parameters: It accepts a single mandatory parameter s which specifies the string to be parsed. Return type: It returns e double value represented by the string argument. Exception: The function throws two exceptions which are described below: NullPointerException- when the string parsed is null NumberFormatException- when the string parsed does not contain a parsable float Below is the implementation of the above method. Program 1: Java // Java Code to implement // parseDouble() method of Double class class GFG { // Driver method public static void main(String[] args) { String str = "100"; // returns the double value // represented by the string argument double val = Double.parseDouble(str); // prints the double value System.out.println("Value = " + val); } } Output: Value = 100.0 Program 2: To show NumberFormatException Java // Java Code to implement // parseDouble() method of Double class class GFG { // Driver method public static void main(String[] args) { try { String str = ""; // returns the double value // represented by the string argument double val = Double.parseDouble(str); // prints the double value System.out.println("Value = " + val); } catch (Exception e) { System.out.println("Exception: " + e); } } } Output: Exception: java.lang.NumberFormatException: empty String Program 3: To show NullPointerException Java // Java Code to implement // parseDouble() method of Double class class GFG { // Driver method public static void main(String[] args) { try { String str = null; // returns the double value // represented by the string argument double val = Double.parseDouble(str); // prints the double value System.out.println("Value = " + val); } catch (Exception e) { System.out.println("Exception: " + e); } } } Output: Exception: java.lang.NullPointerException Reference: https://docs.oracle.com/javase/7/docs/api/java/lang/Double.html#parseDouble(java.lang.String) Comment More infoAdvertise with us Next Article Double parseDouble() method in Java with examples G gopaldave Follow Improve Article Tags : Java java-basics Java-lang package Java-Functions Java-Double +1 More Practice Tags : Java Similar Reads OptionalDouble of(double) method in Java with examples The of(double) method help us to get an OptionalDouble object which contains a double value which is passed as a parameter to this method. Syntax: public static OptionalDouble of(double value) Parameters: This method accepts a double value as parameter that will be set to the returned OptionalDouble 1 min read OptionalDouble orElse(double) method in Java with examples The orElse(double) method helps us to get the value in this OptionalDouble object. If a value is not present in this OptionalDouble, then this method returns the value passed as the parameter. Syntax: public double orElse(double other) Parameters: This method accepts double the value to be returned, 1 min read DoubleAdder sum() method in Java with Examples The java.DoubleAdder.sum() is an inbuilt method in java that returns the current sum. When the object of the class is created its initial value is zero. Syntax: public double sum() Parameters: This method does not accepts any parameter. Return Value: This method returns the current sum. Below progra 1 min read Number.doubleValue() method in java with examples The Number.doubleValue() is an inbuilt method in Java from java.lang.Number package. This method returns the value of the specified number cast as a double data type. This may involve rounding or truncation.Syntax of doubleValue() Methodpublic abstract double doubleValue()Parameters: This method doe 3 min read Short doubleValue() method in Java with Examples The java.lang.Short.doubleValue() method of Short class is a built in method in Java which is used to return the value of the Short object as a double. Syntax: public double doubleValue() Return type: It return the value of ShortObject as double. Below is the implementation of doubleValue() method i 2 min read Like