Java - Write code to parse Double from String

Requirements

Write code to parse Double from String

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str = "book2s.com";
        System.out.println(getDoubleByStr(str));
    }/*  w ww .  java 2 s.co  m*/

    public static Double getDoubleByStr(String str) {
        try {
            Double temp = Double.parseDouble(str);
            return temp;
        } catch (Exception e) {
            return null;
        }
    }
}