Allows to check a string contains a double. - Java java.lang

Java examples for java.lang:String Contain

Description

Allows to check a string contains a double.

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String str = "java2s.com";
        System.out.println(isDouble(str));
    }//from w  w w.j  a  v a 2 s .  co  m

    /**
     * Allows to check a string contains a double.
     * @param str
     *            the string to check
     * @return true if the string is a double, false otherwise
     */
    public static boolean isDouble(final String str) {
        if (str == null) {
            return false;
        }

        try {
            Double.valueOf(str);
        } catch (NumberFormatException e) {
            return false;
        }

        return true;
    }
}

Related Tutorials