Java Basic Examples

Java convert String to double example

This example shows how to convert String to double in Java. This example also shows how to convert String to double primitive using Double wrapper class.

How to convert String to double in Java?

To convert String to double, use parseDouble method of Java Double wrapper class.

This method returns double primitive value by parsing the input String value.

Output

Important Note:

If the input String value cannot be parsed to double value, parseDouble method throws NumberFormatException.

Also, if the String is null, parseDouble method throws NullPointerException.

Output

Here are some of the example String values and their possible output.

Please note that, “+” (plus sign) or “-“(Minus sign) is allowed as a first character of the String to denote positive and negative value number respectively.

Want to learn quickly?
Try one of the many quizzes. I promise you will not be disappointed.

Tags