Here you can find the source of asLong(String value)
Parameter | Description |
---|---|
value | The String value. |
public static Long asLong(String value)
//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; } } }