Java Utililty Methods Long to String

List of utility methods to do Long to String

Description

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

Method

Stringlong2sortableStr(long val)
longsortable Str
char[] arr = new char[5];
long2sortableStr(val, arr, 0);
return new String(arr, 0, 5);
StringLong2Str(long i)
Long Str
String o;
try {
    o = Long.toString(i);
} catch (Exception e) {
    o = "";
return o;
Stringlong2String(final long ip)
Converts a long value representing an IP address to a standard IP address (dotted decimal format).
final long a = (ip & 0xff000000) >> 24;
final long b = (ip & 0x00ff0000) >> 16;
final long c = (ip & 0x0000ff00) >> 8;
final long d = ip & 0xff;
return a + "." + b + "." + c + "." + d;
StringLong2String(final long value)
Long String
if (value >= 0) {
    return String.format("%08x", value);
} else {
    return String.format("-%08x", -value);
voidlong2string(long lng, StringBuilder buff)
longstring
for (int i = 0; i < 16; i++) {
    long nextByte = lng & 0xF000000000000000L;
    lng <<= 4;
    boolean isNegative = nextByte < 0;
    nextByte = rightShift(nextByte, 60);
    if (isNegative) {
        nextByte |= 0x08;
    buff.append(CHARS[(int) nextByte]);
Stringlong2string(long longdata)
longstring
return String.valueOf(longdata);
Stringlong2String(long x)
long String
char[] cArray = long2char(x);
StringBuilder sbResult = new StringBuilder(cArray.length);
for (char c : cArray) {
    sbResult.append(c);
return sbResult.toString();
Stringlong2StringForLen(long num, String str)
long String For Len
int len = String.valueOf(num).length();
if (len > str.length()) {
    return String.valueOf(num).substring(len - str.length(), len);
} else {
    return str.substring(0, str.length() - len) + String.valueOf(num);
byte[]long2Word(long val)
long Word
byte[] ret = new byte[4];
int firstByte = (int) (val & 0xFF000000L) >> 24;
int secondByte = (int) (val & 0x00FF0000L) >> 16;
int thirdByte = (int) (val & 0x0000FF00L) >> 8;
int fourthByte = (int) (val & 0x000000FFL);
ret[0] = (byte) firstByte;
ret[1] = (byte) secondByte;
ret[2] = (byte) thirdByte;
...
StringLongToStr(long nValue)
Long To Str
return new Long(nValue).toString();