Parse Double value from String with default value - Java java.lang

Java examples for java.lang:String Parse

Description

Parse Double value from String with default value

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String value = "java2s.com";
        System.out.println(getDouble(value));
    }/*from   w w  w. jav a 2  s.  com*/

    public static Double getDouble(String value, Double defaultValue) {
        try {
            return Double.valueOf(value);
        } catch (Exception ex) {
            return defaultValue;
        }
    }

    public static Double getDouble(String value) {
        return getDouble(value, null);
    }
}

Related Tutorials