Package java.lang

Class IntegralToString

java.lang.Object
java.lang.IntegralToString

public final class IntegralToString
extends Object
Converts integral types to strings. This class is public but hidden so that it can also be used by java.util.Formatter to speed up %d. This class is in java.lang so that it can take advantage of the package-private String constructor. The most important methods are appendInt/appendLong and intToString(int)/longToString(int). The former are used in the implementation of StringBuilder, StringBuffer, and Formatter, while the latter are used by Integer.toString and Long.toString. The append methods take AbstractStringBuilder rather than Appendable because the latter requires CharSequences, while we only have raw char[]s. Since much of the savings come from not creating any garbage, we can't afford temporary CharSequence instances. One day the performance advantage of the binary/hex/octal specializations will be small enough that we can lose the duplication, but until then this class offers the full set.
  • Method Details

    • intToString

      public static String intToString​(int i, int radix)
      Equivalent to Integer.toString(i, radix).
    • intToString

      public static String intToString​(int i)
      Equivalent to Integer.toString(i).
    • appendInt

      public static void appendInt​(java.lang.AbstractStringBuilder sb, int i)
      Equivalent to sb.append(Integer.toString(i)).
    • longToString

      public static String longToString​(long v, int radix)
      Equivalent to Long.toString(v, radix).
    • longToString

      public static String longToString​(long l)
      Equivalent to Long.toString(l).
    • appendLong

      public static void appendLong​(java.lang.AbstractStringBuilder sb, long l)
      Equivalent to sb.append(Long.toString(l)).
    • intToBinaryString

      public static String intToBinaryString​(int i)
    • longToBinaryString

      public static String longToBinaryString​(long v)
    • appendByteAsHex

      public static StringBuilder appendByteAsHex​(StringBuilder sb, byte b, boolean upperCase)
    • byteToHexString

      public static String byteToHexString​(byte b, boolean upperCase)
    • bytesToHexString

      public static String bytesToHexString​(byte[] bytes, boolean upperCase)
    • intToHexString

      public static String intToHexString​(int i, boolean upperCase, int minWidth)
    • longToHexString

      public static String longToHexString​(long v)
    • intToOctalString

      public static String intToOctalString​(int i)
    • longToOctalString

      public static String longToOctalString​(long v)