Java String to Long asLong(String value)

Here you can find the source of asLong(String value)

Description

Returns the long corresponding to the given string value .

License

Apache License

Parameter

Parameter Description
value The String value.

Return

the integer corresponding to the given string value or null if the value does not contain a parsable long .

Declaration

public static Long asLong(String value) 

Method Source Code

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

public class Main {
    /**//ww  w  .  j  av a2s  .c o m
     * Returns the {@code long} corresponding to the given string {@code value}.
     *
     * @param value
     *         The {@link String} value.
     * @return the integer corresponding to the given string {@code value} or {@code null} if the {@code value} does not
     * contain a parsable {@code long}.
     */
    public static Long asLong(String value) {
        return asLong(value, null);
    }

    /**
     * Returns the {@code long} corresponding to the given string {@code value}.
     *
     * @param value
     *         The {@link String} value.
     * @param defaultValue
     *         The default value returned by the method if the given {@code value} is not a valid {@code long}.
     * @return the integer corresponding to the given string {@code value} or {@code defaultValue} if the {@code value}
     * does not contain a parsable {@code long}.
     */
    public static Long asLong(String value, Long defaultValue) {
        try {
            return Long.parseLong(value);
        } catch (NumberFormatException e) {
            return defaultValue;
        }
    }
}

Related

  1. asLong(String param)
  2. asLong(String str)
  3. asLong(String str, long defaultValue)
  4. asLong(String string)
  5. asLong(String v)
  6. asLong(String value)
  7. atol(final String str, final long def)
  8. atol(String pString_)
  9. atol(String s)