Java Utililty Methods Long Number Create

List of utility methods to do Long Number Create

Description

The list of methods to do Long Number Create are organized into topic(s).

Method

longtoLong(Object value)
to Long
if (value instanceof Number)
    return ((Number) value).longValue();
return Long.parseLong(value.toString());
LongtoLong(Object value)
to Long
if (value == null) {
    return 0L;
} else {
    Long longNum = new Long(value.toString());
    return longNum;
LongtoLong(Object value)
to Long
try {
    if (value == null || EMPTY.equals(value)) {
        return null;
    return Long.valueOf(value.toString());
} catch (Exception e) {
    e.printStackTrace();
    return null;
...
longtoLong(Object value)
to Long
if (value instanceof Number)
    return ((Number) value).longValue();
else if (value == null)
    return 0;
else
    return Long.parseLong(value.toString());
LongtoLong(Object value)
to Long
return toLong(value, 0L);
longtoLong(Object value, long defaultValue)
Converts a generic object value to a long if possible:
  • If value is null the default is returned
  • If value is a Number then its Number#longValue() is returned
  • Otherwise, the value's #toString() is parsed as a long
if (value == null) {
    return defaultValue;
} else if (value instanceof Number) {
    return ((Number) value).longValue();
} else { 
    return Long.parseLong(value.toString());
LongtoLong(Object x)
to Long
if (x == null)
    return null;
if (x instanceof Long)
    return (Long) x;
if (x instanceof Integer)
    return Long.valueOf(((Integer) x).intValue());
if (x instanceof String)
    return Long.valueOf((String) x);
...
long[]toLong(short[] arr)
Converts an array of short values to an array of long values.
int n = arr.length;
long[] converted = new long[n];
for (int i = 0; i < n; i++) {
    converted[i] = arr[i];
return converted;
longtoLong(String input, int radix, long defaultValue)
to Long
try {
    return Long.parseLong(input, radix);
} catch (Exception e) {
    return defaultValue;
longtoLong(String numeric)
to Long
return (isNumeric(numeric)) ? Long.parseLong(numeric) : 0;