public class Main {
public static void main(String[] args) {
String str = "3.14159";
double d = Double.parseDouble(str); // convert string to double
System.out.println("String: " + str);
System.out.println("Double: " + d);
}
}
In this program, we define a String variable str and assign it the value "3.14159". We then use the Double.parseDouble() method to convert this String to a double.
String: 3.14159
Double: 3.14159NumberFormatException will be thrown.