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

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

Description

Convert String to long

License

Apache License

Parameter

Parameter Description
value a parameter
def default value

Declaration

public static long toLong(String value, long def) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*  ww  w  .j  a v a  2  s . c om*/
     * Convert String to long
     * @param value
     * @param def default value
     * @return
     */
    public static long toLong(String value, long def) {
        if (isEmpty(value)) {
            return def;
        }

        try {
            return Long.valueOf(value);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            return def;
        }
    }

    public static boolean isEmpty(String value) {
        return value == null || "".equals(value);
    }
}

Related

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