Here you can find the source of safeParseLong(String number, long fallback)
Parameter | Description |
---|---|
number | String containing the long to be parsed. |
fallback | Number to return if parsing fails. |
public static long safeParseLong(String number, long fallback)
//package com.java2s; public class Main { /**//from ww w . j a v a 2 s. co m * Parse an long from the given string, falling back to the provided number in case of failure. * @param number String containing the long to be parsed. * @param fallback Number to return if parsing fails. * @return Either the parsed number or the fallback. */ public static long safeParseLong(String number, long fallback) { try { return Long.parseLong(number); } catch (NumberFormatException nfe) { return fallback; } } }