Android String to Long Convert safeParseLong(String number, long fallback)

Here you can find the source of safeParseLong(String number, long fallback)

Description

Parse an long from the given string, falling back to the provided number in case of failure.

Parameter

Parameter Description
number String containing the long to be parsed.
fallback Number to return if parsing fails.

Return

Either the parsed number or the fallback.

Declaration

public static long safeParseLong(String number, long fallback) 

Method Source Code

//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;
        }
    }
}

Related

  1. longsToString(long... longs)
  2. parseCSLongs(String s)
  3. parseLong(String s)
  4. parseLongWithDefault(String s, long defValue)
  5. parseLong(String s, long iDefault)