Java Long to String longToString(long longValue, boolean noCase)

Here you can find the source of longToString(long longValue, boolean noCase)

Description

long To String

License

Open Source License

Declaration

public static String longToString(long longValue, boolean noCase) 

Method Source Code

//package com.java2s;

public class Main {
    private static final char[] DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
            .toCharArray();//from  w  ww. ja  v a 2 s.  c om
    private static final char[] DIGITS_NOCASE = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();

    public static String longToString(long longValue) {
        return longToString(longValue, false);
    }

    public static String longToString(long longValue, boolean noCase) {
        char[] digits = noCase ? DIGITS_NOCASE : DIGITS;
        int digitsLength = digits.length;

        if (longValue == 0) {
            return String.valueOf(digits[0]);
        }

        if (longValue < 0) {
            longValue = -longValue;
        }

        StringBuilder strValue = new StringBuilder();

        while (longValue != 0) {
            int digit = (int) (longValue % digitsLength);
            longValue = longValue / digitsLength;

            strValue.append(digits[digit]);
        }

        return strValue.toString();
    }
}

Related

  1. longToString(long l)
  2. LongToString(Long l, int length)
  3. longToString(long li)
  4. longToString(long longV)
  5. longToString(long longValue)
  6. longToString(long n)
  7. LongToString(long number, boolean bcdFlag, int bufferSize)
  8. longToString(long val)
  9. longToString(long value)