src/share/classes/java/lang/Integer.java

Print this page
rev 5431 : 6924259: Remove offset and count fields from java.lang.String
Summary: Removes the use of shared character array buffers by String along with the two fields needed to support the use of shared buffers.
Contributed-by: brian.doherty@oracle.com


 364         //      T Gralund, P Montgomery
 365         //      ACM PLDI 1994
 366         //
 367 
 368     /**
 369      * Returns a {@code String} object representing the
 370      * specified integer. The argument is converted to signed decimal
 371      * representation and returned as a string, exactly as if the
 372      * argument and radix 10 were given as arguments to the {@link
 373      * #toString(int, int)} method.
 374      *
 375      * @param   i   an integer to be converted.
 376      * @return  a string representation of the argument in base 10.
 377      */
 378     public static String toString(int i) {
 379         if (i == Integer.MIN_VALUE)
 380             return "-2147483648";
 381         int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
 382         char[] buf = new char[size];
 383         getChars(i, size, buf);
 384         return new String(0, size, buf);
 385     }
 386 
 387     /**
 388      * Returns a string representation of the argument as an unsigned
 389      * decimal value.
 390      *
 391      * The argument is converted to unsigned decimal representation
 392      * and returned as a string exactly as if the argument and radix
 393      * 10 were given as arguments to the {@link #toUnsignedString(int,
 394      * int)} method.
 395      *
 396      * @param   i  an integer to be converted to an unsigned string.
 397      * @return  an unsigned string representation of the argument.
 398      * @see     #toUnsignedString(int, int)
 399      * @since 1.8
 400      */
 401     public static String toUnsignedString(int i) {
 402         return Long.toString(toUnsignedLong(i));
 403     }
 404 




 364         //      T Gralund, P Montgomery
 365         //      ACM PLDI 1994
 366         //
 367 
 368     /**
 369      * Returns a {@code String} object representing the
 370      * specified integer. The argument is converted to signed decimal
 371      * representation and returned as a string, exactly as if the
 372      * argument and radix 10 were given as arguments to the {@link
 373      * #toString(int, int)} method.
 374      *
 375      * @param   i   an integer to be converted.
 376      * @return  a string representation of the argument in base&nbsp;10.
 377      */
 378     public static String toString(int i) {
 379         if (i == Integer.MIN_VALUE)
 380             return "-2147483648";
 381         int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
 382         char[] buf = new char[size];
 383         getChars(i, size, buf);
 384         return new String(buf, true);
 385     }
 386 
 387     /**
 388      * Returns a string representation of the argument as an unsigned
 389      * decimal value.
 390      *
 391      * The argument is converted to unsigned decimal representation
 392      * and returned as a string exactly as if the argument and radix
 393      * 10 were given as arguments to the {@link #toUnsignedString(int,
 394      * int)} method.
 395      *
 396      * @param   i  an integer to be converted to an unsigned string.
 397      * @return  an unsigned string representation of the argument.
 398      * @see     #toUnsignedString(int, int)
 399      * @since 1.8
 400      */
 401     public static String toUnsignedString(int i) {
 402         return Long.toString(toUnsignedLong(i));
 403     }
 404