Android String to Long Convert getLongValue(String value, Long defaultValue)

Here you can find the source of getLongValue(String value, Long defaultValue)

Description

Gets the long value from string.

Parameter

Parameter Description
value the string value.
defaultValue the default value.

Return

the parsed long value, otherwise defaultValue.

Declaration

public static Long getLongValue(String value, Long defaultValue) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from w  ww  .ja  va  2 s . c o m*/
     * Gets the long value from string.
     *
     * @param value        the string value.
     * @param defaultValue the default value.
     * @return the parsed long value, otherwise defaultValue.
     */
    public static Long getLongValue(String value, Long defaultValue) {
        try {
            if (value != null && value.length() > 0) {
                return Long.parseLong(value);
            }
        } catch (NumberFormatException e) {
            // do nothing
        }
        return defaultValue;
    }
}

Related

  1. parseLong(String s)
  2. toLong(String obj)
  3. isLong(String str)
  4. getLongValue(String str)
  5. stringToListLong(String input)