Java Integer to String intToString(final int param)

Here you can find the source of intToString(final int param)

Description

convert an integer to a string.

License

Open Source License

Parameter

Parameter Description
param An integer to convert

Return

a string representation

Declaration

public static String intToString(final int param) 

Method Source Code

//package com.java2s;
/*/*from www . j  a  va  2s.c  om*/
 * Utility.java
 *
 * HomePage :  http://www.codeproject.com/csharp/TraceTool.asp
 * Download :  http://sourceforge.net/projects/tracetool/
 * See License.txt for license information
 *
 * Author : Thierry Parent
 * Version : 12.3
 *
 * Provide some utility functions
 */

public class Main {
    /**
     * convert an integer to a string.
     * @param param An integer to convert
     * @return a string representation
     * @see #intToString(int, int) for formatted string
     */
    public static String intToString(final int param) {
        return Integer.toString(param);
    }

    /**
     * convert an integer to a string (left padding).
     * @param param  An integer to convert
     * @param len The string length
     * @return a string representation
     */
    public static String intToString(final int param, final int len) {
        return intToStringBuffer(param, len).toString();
    }

    /**
     * convert an integer to a StringBuffer (left padding).
     * @param param  An integer to convert
     * @param len The string length
     * @return a string representation
     */
    public static StringBuffer intToStringBuffer(final int param, final int len) {
        StringBuffer temp = new StringBuffer(Integer.toString(param));
        leftPadding(temp, len, ' ');
        return temp;
    }

    /**
     * Left Pad Stringbuffer with special char
     * @param strBuf Target buffer
     * @param bufLen Buffer length
     * @param fill Char to fill
     * @return a padded StringBuffer
     */
    public static StringBuffer leftPadding(final StringBuffer strBuf, final int bufLen, final char fill) {
        while (strBuf.length() < bufLen)
            strBuf.insert(0, fill);
        return strBuf;
    }
}

Related

  1. intToStr(int valor, int len)
  2. intToStr(int value)
  3. intToStr(int value, int len)
  4. inttostr(String intStr)
  5. intToStr3(final int param)
  6. intToString(final int value)
  7. intToString(final Integer value)
  8. intToString(final long v, final int length)
  9. intToString(int i)