Java Long Number Create toLong(String value, long defaultValue)

Here you can find the source of toLong(String value, long defaultValue)

Description

convert the string to an long, and return the default value if the string is null or does not contain a valid int value

License

Open Source License

Parameter

Parameter Description
value string value
defaultValue default value

Return

long

Declaration

static public long toLong(String value, long defaultValue) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from w  ww .j  a  v a  2 s . c  o m*/
     * convert the string to an long, and return the default value if
     * the string is null or does not contain a valid int value
     *
     * @param value string value
     * @param defaultValue default value
     *
     * @return long
     */
    static public long toLong(String value, long defaultValue) {
        if (value != null) {
            try {
                return Long.parseLong(value);
            } catch (NumberFormatException n) {
            }
        }
        return defaultValue;
    }

    /**
     * convert the string to an long, and return 0 if
     * the string is null or does not contain a valid int value
     *
     * @param value string value
     *
     * @return long
     */
    static public long toLong(String value) {
        if (value != null) {
            try {
                return Long.parseLong(value);
            } catch (NumberFormatException n) {
            }
        }
        return 0;
    }
}

Related

  1. toLong(String value)
  2. toLong(String value)
  3. toLong(String value, long _default)
  4. toLong(String value, long def)
  5. toLong(String value, Long defaultValue)
  6. toLong(String value, Long defaultValue)
  7. toLong(T value)
  8. toLongObject(Object o)