Android Utililty Methods String to Long Convert

List of utility methods to do String to Long Convert

Description

The list of methods to do String to Long Convert are organized into topic(s).

Method

LongstringToLong(String input)
string To Long
try {
    return Long.parseLong(input);
} catch (NumberFormatException e) {
    return 0l;
StringlongsToString(long... longs)
longs To String
StringBuilder string = new StringBuilder();
for (int i = 0; i < longs.length; i++) {
    long aLong = longs[i];
    string.append(aLong);
    if (i + 1 < longs.length)
        string.append(",");
return string.toString();
...
long[]parseCSLongs(String s)
parse CS Longs
if (s == null) {
    return null;
String[] elements = s.split(",");
long[] result = new long[elements.length];
for (int index = 0; index < elements.length; index++) {
    Long value = parseLong(elements[index]);
    if (value != null) {
...
LongparseLong(String s)
parse Long
try {
    return new Long(s);
} catch (NumberFormatException e) {
    return null;
longparseLongWithDefault(String s, long defValue)
parse Long With Default
if (s == null) {
    return defValue;
try {
    return Long.parseLong(s);
} catch (NumberFormatException e) {
    return defValue;
longparseLong(String s, long iDefault)
Parses the long value of the specified string.
if (s == null || s.equals(""))
    return iDefault;
try {
    s = s.trim().replaceAll(",", "");
    final int l = s.indexOf('.');
    if (l > 0)
        s = s.substring(0, l);
    return Long.parseLong(s);
...
longsafeParseLong(String number, long fallback)
Parse an long from the given string, falling back to the provided number in case of failure.
try {
    return Long.parseLong(number);
} catch (NumberFormatException nfe) {
    return fallback;